Changeset 2048 in MondoRescue for branches/2.2.8/mondo/src/common/libmondo-files.c
- Timestamp:
- Oct 22, 2008, 6:53:57 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.8/mondo/src/common/libmondo-files.c
r1836 r2048 793 793 paranoid_fclose(fin); 794 794 return (matches); 795 }796 797 798 799 800 /**801 * Register our PID in a file in /var/run.802 * The PID will be put in /var/run/monitas-<tt>name_str</tt>.pid.803 * @param pid 0 to remove file, anything else to create it.804 * @param name_str The basename of the PID file (e.g. "mondo" or "server")805 * @note This function does not provide support against multiple instances, unless you check for that yourself.806 */807 void register_pid(pid_t pid, char *name_str)808 {809 char tmp[MAX_STR_LEN + 1], lockfile_fname[MAX_STR_LEN + 1];810 int res;811 FILE *fin;812 813 sprintf(lockfile_fname, "/var/run/monitas-%s.pid", name_str);814 if (!pid) {815 log_it("Unregistering PID");816 if (unlink(lockfile_fname)) {817 log_it("Error unregistering PID");818 }819 return;820 }821 if (does_file_exist(lockfile_fname)) {822 tmp[0] = '\0';823 if ((fin = fopen(lockfile_fname, "r"))) {824 (void) fgets(tmp, MAX_STR_LEN, fin);825 paranoid_fclose(fin);826 } else {827 log_OS_error("Unable to openin lockfile_fname");828 }829 pid = (pid_t) atol(tmp);830 sprintf(tmp, "ps %ld > /dev/null 2> /dev/null", (long int) pid);831 res = system(tmp);832 if (!res) {833 log_it834 ("I believe the daemon is already running. If it isn't, please delete %s and try again.",835 lockfile_fname);836 }837 }838 sprintf(tmp, "echo %ld > %s 2> /dev/null", (long int) getpid(),839 lockfile_fname);840 if (system(tmp)) {841 fatal_error("Cannot register PID");842 }843 795 } 844 796
Note:
See TracChangeset
for help on using the changeset viewer.