From: Timo Kokkonen Date: Sat, 9 Jul 2016 06:50:07 +0000 (+0300) Subject: process: Make run() execute synchronously X-Git-Url: http://git.itanic.dy.fi/?p=rrdd;a=commitdiff_plain;h=ac609eaad1b9788d77c5e42e570ad476625c66d1 process: Make run() execute synchronously Currently there are no need for running the process asynchronously on background, so we might just make it run synchronously instead. This simplifies the calling convention and also removes completely the need to fork and possibly race in glibc functions. Signed-off-by: Timo Kokkonen --- diff --git a/process.c b/process.c index 8d3d18f..b4319fe 100644 --- a/process.c +++ b/process.c @@ -751,9 +751,6 @@ int run(const char *cmd, char *const argv[]) int maxfd; int eof = 0; - if ((child = do_fork())) - return child; - child = run_piped(cmd, argv, NULL, &ofd, &efd); FD_ZERO(&rfds); @@ -828,7 +825,6 @@ print: harvest_zombies(child); - exit(1); return 0; } diff --git a/rrdtool.c b/rrdtool.c index 58c0f57..be62321 100644 --- a/rrdtool.c +++ b/rrdtool.c @@ -91,8 +91,7 @@ int rrdtool_draw_image(struct rrd_image *image) add_arg(args, argcnt, argstr, idx, "COMMENT: %s\\c", timestamp); - pid = run(cmd, args); - harvest_zombies(pid); + run(cmd, args); rename(tmpfile, image->image_filename); @@ -278,13 +277,11 @@ static int do_rrdtool_update_data(struct rrd_database *rrd) sanitize_rrd_update_data(data + l); write_to_logfile(rrd, data); - pid = run(cmd, cmdline); - harvest_zombies(pid); + run(cmd, cmdline); } if (rrd->pre_draw_cmd && !strcmp(rrd->pre_draw_cmd[0], "shell")) { - pid = run(rrd->pre_draw_cmd[1], &rrd->pre_draw_cmd[1]); - harvest_zombies(pid); + run(rrd->pre_draw_cmd[1], &rrd->pre_draw_cmd[1]); } if (rrd->images) @@ -362,7 +359,7 @@ static int create_database(struct rrd_database *db) // char cmd[] = "echo"; char *args[512], argstr[ARGSTR_LEN]; int idx = 0, argcnt = 0; - int child, i; + int i; if (!db->filename) { pr_err("Database %s missing database filename\n", db->name); @@ -398,9 +395,7 @@ static int create_database(struct rrd_database *db) db->archives[i].rows); } - child = run(cmd, args); - - harvest_zombies(child); + run(cmd, args); return 0; }