The open source OpenXR runtime

a/util: proceed pidfile creation if EEXIST

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2420>

authored by

Simon Zeni and committed by
Marge Bot
dfa1c423 74772316

+6 -6
+6 -6
src/xrt/auxiliary/util/u_process.c
··· 52 52 u_process_create_if_not_running(void) 53 53 { 54 54 #ifdef XRT_HAVE_LIBBSD 55 - 56 - char tmp[PATH_MAX]; 55 + char tmp[PATH_MAX] = {0}; 57 56 if (get_pidfile_path(tmp) < 0) { 58 57 U_LOG_W("Failed to determine runtime dir, not creating pidfile"); 59 58 return NULL; ··· 62 61 U_LOG_T("Using pidfile %s", tmp); 63 62 64 63 pid_t otherpid; 65 - 66 64 struct pidfh *pfh = pidfile_open(tmp, 0600, &otherpid); 67 - if (errno == EEXIST || pfh == NULL) { 68 - U_LOG_T("Failed to create pidfile (%s): Another Monado instance may be running", strerror(errno)); 65 + if (pfh == NULL) { 69 66 // other process is locking pid file 67 + if (errno == EEXIST) { 68 + U_LOG_E("Monado is already running, pid %d", otherpid); 69 + } 70 + U_LOG_E("Failed to create pidfile: %s", strerror(errno)); 70 71 return NULL; 71 72 } 72 73 73 74 // either new or stale pidfile opened 74 - 75 75 int write_ret = pidfile_write(pfh); 76 76 if (write_ret != 0) { 77 77 pidfile_close(pfh);