All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit d1a7e2ba authored by Leigh B Stoller's avatar Leigh B Stoller

Cleanup init/remote of the pidfile in /var/run.

parent b8bf6903
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2004, 2006, 2007 University of Utah and the Flux Group.
* Copyright (c) 2000-2010 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -9,6 +9,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <sys/param.h>
#include <paths.h>
#include <unistd.h>
#include <stdlib.h>
......@@ -32,6 +33,7 @@
static void log_bootwhat(struct in_addr ipaddr, boot_what_t *bootinfo);
static void onhup(int sig);
static char *progname;
static char pidfile[MAXPATHLEN];
int debug = 0;
void
......@@ -46,6 +48,12 @@ usage()
exit(-1);
}
static void
cleanup()
{
unlink(pidfile);
}
int
main(int argc, char **argv)
{
......@@ -53,7 +61,6 @@ main(int argc, char **argv)
struct sockaddr_in name, client;
boot_info_t boot_info;
int port = BOOTWHAT_DSTPORT;
char buf[BUFSIZ];
FILE *fp;
extern char build_info[];
......@@ -92,11 +99,12 @@ main(int argc, char **argv)
}
info("%s\n", build_info);
signal(SIGTERM, cleanup);
/*
* Write out a pidfile.
*/
sprintf(buf, "%s/bootinfo.pid", _PATH_VARRUN);
fp = fopen(buf, "w");
sprintf(pidfile, "%s/bootinfo.pid", _PATH_VARRUN);
fp = fopen(pidfile, "w");
if (fp != NULL) {
fprintf(fp, "%d\n", getpid());
(void) fclose(fp);
......
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2003 University of Utah and the Flux Group.
* Copyright (c) 2000-2010 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -9,6 +9,7 @@
*/
#include "hmcd.h"
#include <paths.h>
#ifndef LOG_TESTBED
#define LOG_TESTBED LOG_DAEMON
......@@ -17,6 +18,7 @@
void AcceptClient(int, int*);
void CollectData(int, HMONENT*);
int EmitData(int, HMONENT*);
char *Pidname;
void lerror(const char* msgstr) {
if (msgstr) {
......@@ -37,6 +39,8 @@ void siginthandler(int signum) {
lerror("Couldn't remove UNIX socket");
exit(1);
}
if (Pidname)
(void) unlink(Pidname);
lnotice("Daemon exiting.");
exit(0);
}
......@@ -120,6 +124,18 @@ int main(int argc, char **argv) {
lerror("Couldn't become daemon");
exit(1);
}
if (!getuid()) {
FILE *fp;
char mybuf[BUFSIZ];
sprintf(mybuf, "%s/hmcd.pid", _PATH_VARRUN);
fp = fopen(mybuf, "w");
if (fp != NULL) {
fprintf(fp, "%d\n", getpid());
(void) fclose(fp);
Pidname = strdup(mybuf);
}
}
lnotice("Daemon started successfully");
......
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2003 University of Utah and the Flux Group.
* Copyright (c) 2000-2010 University of Utah and the Flux Group.
* All rights reserved.
*/
#include "sdcollectd.h"
#include <paths.h>
void siginthandler(int signum) {
char *Pidname;
void siginthandler(int signum) {
if (Pidname)
(void) unlink(Pidname);
info("Daemon exiting.\n");
exit(0);
}
......@@ -123,6 +127,19 @@ int main(int argc, char **argv) {
info(build_info);
}
if (!getuid()) {
FILE *fp;
char mybuf[BUFSIZ];
sprintf(mybuf, "%s/sdcollectd.pid", _PATH_VARRUN);
fp = fopen(mybuf, "w");
if (fp != NULL) {
fprintf(fp, "%d\n", getpid());
(void) fclose(fp);
Pidname = strdup(mybuf);
}
}
/*
* Change to non-root user!
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment