summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2017-07-31 15:20:19 +1000
committerMartin Schwenke <martins@samba.org>2017-08-02 03:39:12 +0200
commit09b03988650b68897c02a521d570737578c72d85 (patch)
treee8d0bd02c7a09eba1977255570f035143b436a04 /lib/util
parent411b7c87536a8639954bf1eb6876209abfb4e848 (diff)
downloadsamba-09b03988650b68897c02a521d570737578c72d85.tar.gz
util: Reimplement pidfile_create() using pidfile_path_create()
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/pidfile.c27
1 files changed, 5 insertions, 22 deletions
diff --git a/lib/util/pidfile.c b/lib/util/pidfile.c
index 2be61966e26..fdf9afb5ec9 100644
--- a/lib/util/pidfile.c
+++ b/lib/util/pidfile.c
@@ -191,9 +191,8 @@ void pidfile_create(const char *piddir, const char *name)
{
size_t len = strlen(piddir) + strlen(name) + 6;
char pidFile[len];
- int fd;
- char buf[20];
pid_t pid;
+ int ret;
snprintf(pidFile, sizeof(pidFile), "%s/%s.pid", piddir, name);
@@ -204,26 +203,10 @@ void pidfile_create(const char *piddir, const char *name)
exit(1);
}
- fd = open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY, 0644);
- if (fd == -1) {
- DEBUG(0,("ERROR: can't open %s: Error was %s\n", pidFile,
- strerror(errno)));
- exit(1);
- }
-
- smb_set_close_on_exec(fd);
-
- if (fcntl_lock(fd,F_SETLK,0,1,F_WRLCK)==false) {
- DEBUG(0,("ERROR: %s : fcntl lock of file %s failed. Error was %s\n",
- name, pidFile, strerror(errno)));
- exit(1);
- }
-
- memset(buf, 0, sizeof(buf));
- slprintf(buf, sizeof(buf) - 1, "%u\n", (unsigned int) getpid());
- if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) {
- DEBUG(0,("ERROR: can't write to file %s: %s\n",
- pidFile, strerror(errno)));
+ ret = pidfile_path_create(pidFile, NULL);
+ if (ret != 0) {
+ DBG_ERR("ERROR: Failed to create PID file %s (%s)\n",
+ pidFile, strerror(ret));
exit(1);
}