"/sbin/init",
'\0',
};
- FILE *pid_fp = NULL;
struct lxc_container *c;
lxc_list_init(&defines);
ERROR("failed to ensure pidfile '%s'", my_args.pidfile);
goto out;
}
-
- pid_fp = fopen(my_args.pidfile, "w");
- if (pid_fp == NULL) {
- SYSERROR("failed to create pidfile '%s' for '%s'",
- my_args.pidfile, my_args.name);
- goto out;
- }
}
int i;
c->want_daemonize(c, false);
}
- if (pid_fp != NULL) {
- if (fprintf(pid_fp, "%d\n", getpid()) < 0) {
- SYSERROR("failed to write '%s'", my_args.pidfile);
- goto out;
- }
- fclose(pid_fp);
- pid_fp = NULL;
- }
-
if (my_args.close_all_fds)
c->want_close_all_fds(c, true);
err = c->start(c, 0, args) ? 0 : -1;
out:
lxc_container_put(c);
- if (pid_fp)
- fclose(pid_fp);
return err;
}
int ret;
struct lxc_conf *conf;
bool daemonize = false;
+ FILE *pid_fp = NULL;
char *default_args[] = {
"/sbin/init",
'\0',
pid_t pid = fork();
if (pid < 0)
return false;
- if (pid != 0)
+
+ if (pid != 0) {
+ /* Set to NULL because we don't want father unlink
+ * the PID file, child will do the free and unlink.
+ */
+ c->pidfile = NULL;
return wait_on_daemonized_start(c, pid);
+ }
/* second fork to be reparented by init */
pid = fork();
}
}
+ /* We need to write PID file after daeminize, so we always
+ * write the right PID.
+ */
+ if (c->pidfile) {
+ pid_fp = fopen(c->pidfile, "w");
+ if (pid_fp == NULL) {
+ SYSERROR("Failed to create pidfile '%s' for '%s'",
+ c->pidfile, c->name);
+ return false;
+ }
+
+ if (fprintf(pid_fp, "%d\n", getpid()) < 0) {
+ SYSERROR("Failed to write '%s'", c->pidfile);
+ fclose(pid_fp);
+ pid_fp = NULL;
+ return false;
+ }
+
+ fclose(pid_fp);
+ pid_fp = NULL;
+ }
+
reboot:
conf->reboot = 0;
ret = lxc_start(c->name, argv, conf, c->config_path);