1 /* this code is broken - there is a race condition with the unlink (tridge) */
4 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 1998
7 Copyright (C) Jeremy Allison 2012
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "system/filesys.h"
25 #include "../lib/util/pidfile.h"
27 /* Malloc a pidfile name. */
28 static char *get_pidfile_name(const char *program_name
)
32 /* Add a suffix to the program name if this is a process with a
33 * none default configuration file name. */
34 if (strcmp( CONFIGFILE
, get_dyn_CONFIGFILE()) == 0) {
35 name
= SMB_STRDUP(program_name
);
37 const char *short_configfile
;
38 short_configfile
= strrchr( get_dyn_CONFIGFILE(), '/');
39 if (short_configfile
== NULL
) {
40 /* conf file in current directory */
41 short_configfile
= get_dyn_CONFIGFILE();
43 /* full/relative path provided */
46 if (asprintf(&name
, "%s-%s", program_name
,
47 short_configfile
) == -1) {
48 smb_panic("asprintf failed");
54 /* return the pid in a pidfile. return 0 if the process (or pidfile)
56 pid_t
pidfile_pid_s3(const char *program_name
)
59 char *name
= get_pidfile_name(program_name
);
61 pid
= pidfile_pid(lp_piddir(), name
);
66 /* create a pid file in the pid directory. open it and leave it locked */
67 void pidfile_create_s3(const char *program_name
)
69 char *name
= get_pidfile_name(program_name
);
71 pidfile_create(lp_piddir(), name
);
75 /* Remove a pidfile. */
76 void pidfile_unlink_s3(const char *program_name
)
78 char *name
= get_pidfile_name(program_name
);
79 pidfile_unlink(lp_piddir(), name
);