<arg choice="opt">-f <replaceable>config_file</replaceable></arg>
<arg choice="opt">-c <replaceable>console_file</replaceable></arg>
<arg choice="opt">-d</arg>
+ <arg choice="opt">-p <replaceable>pid_file</replaceable></arg>
<arg choice="opt">-s KEY=VAL</arg>
<arg choice="opt">-C</arg>
<arg choice="opt">command</arg>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>
+ <option>-p, --pidfile <replaceable>pid_file</replaceable></option>
+ </term>
+ <listitem>
+ <para>
+ Create a file with the process id.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term>
<option>-f, --rcfile <replaceable>config_file</replaceable></option>
case 'f': args->rcfile = arg; break;
case 'C': args->close_all_fds = 1; break;
case 's': return lxc_config_define_add(&defines, arg);
+ case 'p': args->pidfile = arg; break;
}
return 0;
}
{"define", required_argument, 0, 's'},
{"console", required_argument, 0, 'c'},
{"close-all-fds", no_argument, 0, 'C'},
+ {"pidfile", required_argument, 0, 'p'},
LXC_COMMON_OPTIONS
};
Options :\n\
-n, --name=NAME NAME for name of the container\n\
-d, --daemon daemonize the container\n\
+ -p, --pidfile=FILE Create a file with the process id\n\
-f, --rcfile=FILE Load configuration file FILE\n\
-c, --console=FILE Set the file output for the container console\n\
-C, --close-all-fds If any fds are inherited, close them\n\
.parser = my_parser,
.checker = NULL,
.daemonize = 0,
+ .pidfile = NULL,
};
int main(int argc, char *argv[])
"/sbin/init",
'\0',
};
+ FILE *pid_fp = NULL;
lxc_list_init(&defines);
free(console);
}
+ if (my_args.pidfile != NULL) {
+ pid_fp = fopen(my_args.pidfile, "w");
+ if (pid_fp == NULL) {
+ SYSERROR("failed to create '%s'", my_args.name);
+ return err;
+ }
+ }
+
if (my_args.daemonize) {
/* do an early check for needed privs, since otherwise the
* user won't see the error */
}
}
+ if (pid_fp != NULL) {
+ if (fprintf(pid_fp, "%d\n", getpid()) < 0) {
+ SYSERROR("failed to write '%s'", my_args.pidfile);
+ return err;
+ }
+ fclose(pid_fp);
+ }
+
if (my_args.close_all_fds)
conf->close_all_fds = 1;
err = -1;
}
+ if (my_args.pidfile)
+ unlink(my_args.pidfile);
+
return err;
}