From b02b417084b3607a8e9afe6d835518d5900f516b Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 19 Jun 2007 17:25:48 +0000 Subject: [PATCH] Add the -p pidfile option to the vkernel. Submitted-by: Chris Turner --- share/man/man7/vkernel.7 | 6 +++- sys/platform/vkernel/platform/init.c | 46 ++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/share/man/man7/vkernel.7 b/share/man/man7/vkernel.7 index 22790f4528..e77de6ac4b 100644 --- a/share/man/man7/vkernel.7 +++ b/share/man/man7/vkernel.7 @@ -29,7 +29,7 @@ .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $DragonFly: src/share/man/man7/vkernel.7,v 1.19 2007/06/17 16:46:14 dillon Exp $ +.\" $DragonFly: src/share/man/man7/vkernel.7,v 1.20 2007/06/19 17:25:46 dillon Exp $ .\" .Dd June 14, 2007 .Dt VKERNEL 7 @@ -51,6 +51,7 @@ .Op Fl i Ar file .Op Fl I Ar interface Ns Op Ar :address1 Ns Oo Ar :address2 Oc Ns Oo Ar /netmask Oc .Op Fl m Ar size +.Op Fl p Ar file .Op Fl r Ar file .Sh DESCRIPTION The @@ -149,6 +150,9 @@ Lowercase versions of and .Cm G are allowed. +.It Fl p Ar file +Specify a file in which to store the process ID. +A warning is issued if this file cannot be opened for writing. .It Fl r Ar file Specify a R/W disk image .Ar file diff --git a/sys/platform/vkernel/platform/init.c b/sys/platform/vkernel/platform/init.c index a8575b743b..789c679c9c 100644 --- a/sys/platform/vkernel/platform/init.c +++ b/sys/platform/vkernel/platform/init.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/platform/vkernel/platform/init.c,v 1.39 2007/05/28 05:26:29 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/platform/init.c,v 1.40 2007/06/19 17:25:48 dillon Exp $ */ #include @@ -80,6 +80,7 @@ struct vkdisk_info DiskInfo[VKDISK_MAX]; int DiskNum; struct vknetif_info NetifInfo[VKNETIF_MAX]; int NetifNum; +char *pid_file; vm_offset_t KvaStart; vm_offset_t KvaEnd; vm_offset_t KvaSize; @@ -107,6 +108,8 @@ static void init_globaldata(void); static void init_vkernel(void); static void init_disk(char *diskExp[], int diskFileNum, enum vkdisk_type type); static void init_netif(char *netifExp[], int netifFileNum); +static void writepid( void ); +static void cleanpid( void ); static void usage(const char *ctl); static int save_ac; @@ -129,7 +132,7 @@ main(int ac, char **av) int c; int i; int n; - + save_ac = ac; save_av = av; @@ -138,7 +141,7 @@ main(int ac, char **av) */ kernel_mem_readonly = 1; - while ((c = getopt(ac, av, "c:svm:r:e:i:I:U")) != -1) { + while ((c = getopt(ac, av, "c:svm:r:e:i:p:I:U")) != -1) { switch(c) { case 'e': /* @@ -200,12 +203,16 @@ main(int ac, char **av) } } break; + case 'p': + pid_file = optarg; + break; case 'U': kernel_mem_readonly = 0; break; } } + writepid(); cpu_disable_intr(); init_sys_memory(memImageFile); init_kern_memory(); @@ -1037,6 +1044,37 @@ init_netif(char *netifExp[], int netifExpNum) close(s); } +static +void +writepid( void ) +{ + pid_t self; + FILE *fp; + + if (pid_file != NULL) { + self = getpid(); + fp = fopen(pid_file, "w"); + + if (fp != NULL) { + fprintf(fp, "%ld\n", (long)self); + fclose(fp); + } + else { + perror("Warning: couldn't open pidfile"); + } + } +} + +static +void +cleanpid( void ) +{ + if (pid_file != NULL) { + if ( unlink(pid_file) != 0 ) + perror("Warning: couldn't remove pidfile"); + } +} + static void usage(const char *ctl) @@ -1049,6 +1087,7 @@ cpu_reset(void) { kprintf("cpu reset, rebooting vkernel\n"); closefrom(3); + cleanpid(); execv(save_av[0], save_av); } @@ -1056,5 +1095,6 @@ void cpu_halt(void) { kprintf("cpu halt, exiting vkernel\n"); + cleanpid(); exit(0); } -- 2.41.0