107
113
static void usage(char *name);
118
static bool _pid_write(const char *pid_file)
122
f= fopen(pid_file, "w");
125
fprintf(stderr, "gearmand: Could not open pid file for writing: %s (%d)\n",
130
fprintf(f, "%" PRId64 "\n", (int64_t)getpid());
134
fprintf(stderr, "gearmand: Could not close the pid file: %s (%d)\n",
142
static void _pid_delete(const char *pid_file)
144
if (unlink(pid_file) == -1)
146
fprintf(stderr, "gearmand: Could not remove the pid file: %s (%d)\n",
109
151
int main(int argc, char *argv[])
112
154
gearman_args_st args;
155
bool close_stdio= false;
114
157
memset(&args, 0, sizeof(gearman_args_st));
115
158
args.priority= GEARMAN_JOB_PRIORITY_NORMAL;
120
163
if (args.function == NULL)
121
164
GEARMAN_ERROR("malloc:%d", errno)
123
while ((c = getopt(argc, argv, "bc:f:h:HILnNp:Pst:u:w")) != -1)
166
while ((c = getopt(argc, argv, "bc:f:h:HILnNp:Pst:u:wi:d")) != -1)
192
243
args.argv= argv + optind;
194
245
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
195
GEARMAN_ERROR("signal:%d", errno)
246
GEARMAN_ERROR("signal:%d", errno);
253
fprintf(stderr, "gearmand: fork:%d\n", errno);
265
fprintf(stderr, "gearmand: setsid:%d\n", errno);
276
/* If we can't remap stdio, it should not a fatal error. */
277
fd= open("/dev/null", O_RDWR, 0);
281
if (dup2(fd, STDIN_FILENO) == -1)
283
fprintf(stderr, "gearmand: dup2:%d\n", errno);
287
if (dup2(fd, STDOUT_FILENO) == -1)
289
fprintf(stderr, "gearmand: dup2:%d\n", errno);
293
if (dup2(fd, STDERR_FILENO) == -1)
295
fprintf(stderr, "gearmand: dup2:%d\n", errno);
303
if (args.pid_file != NULL && _pid_write(args.pid_file))
311
if (args.pid_file != NULL)
313
_pid_delete(args.pid_file);
202
317
return args.return_value;
621
736
printf("\t-H - Print this help menu\n");
622
737
printf("\t-p <port> - Job server port\n");
623
738
printf("\t-t <timeout> - Timeout in milliseconds\n");
739
printf("\t-i <pidfile> - Create a pidfile for the process\n");
625
741
printf("\nClient options:\n");
626
742
printf("\t-b - Run jobs in the background\n");