From: Amitay Isaacs Date: Mon, 3 Aug 2015 05:02:43 +0000 (+1000) Subject: ctdb-system: Remove unused system specific calls X-Git-Tag: talloc-2.1.4~433 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9030d8c10ebe6f95f33cbc691b5756d97395b0f;p=thirdparty%2Fsamba.git ctdb-system: Remove unused system specific calls Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- diff --git a/ctdb/common/system_aix.c b/ctdb/common/system_aix.c index 41f61aecb5d..a98d3820567 100644 --- a/ctdb/common/system_aix.c +++ b/ctdb/common/system_aix.c @@ -374,26 +374,8 @@ int ctdb_get_peer_pid(const int fd, pid_t *peer_pid) return ret; } -char *ctdb_get_process_name(pid_t pid) -{ - /* FIXME AIX: get_process_name not implemented */ - return NULL; -} - int ctdb_set_process_name(const char *name) { /* FIXME AIX: set_process_name not implemented */ return -ENOSYS; } - -bool ctdb_get_lock_info(pid_t req_pid, struct ctdb_lock_info *lock_info) -{ - /* FIXME AIX: get_lock_info not implemented */ - return false; -} - -bool ctdb_get_blocker_pid(struct ctdb_lock_info *reqlock, pid_t *blocker_pid) -{ - /* FIXME AIX: get_blocker_pid not implemented */ - return false; -} diff --git a/ctdb/common/system_freebsd.c b/ctdb/common/system_freebsd.c index 9597a7ac965..c5a816bf7af 100644 --- a/ctdb/common/system_freebsd.c +++ b/ctdb/common/system_freebsd.c @@ -370,40 +370,8 @@ int ctdb_get_peer_pid(const int fd, pid_t *peer_pid) return 1; } -char *ctdb_get_process_name(pid_t pid) -{ - char path[32]; - char buf[PATH_MAX]; - char *ptr; - int n; - - snprintf(path, sizeof(path), "/proc/%d/exe", pid); - n = readlink(path, buf, sizeof(buf)); - if (n < 0) { - return NULL; - } - - /* Remove any extra fields */ - buf[n] = '\0'; - ptr = strtok(buf, " "); - return strdup(ptr); - return NULL; -} - int ctdb_set_process_name(const char *name) { /* FIXME FreeBSD: set_process_name not implemented */ return -ENOSYS; } - -bool ctdb_get_lock_info(pid_t req_pid, struct ctdb_lock_info *lock_info) -{ - /* FIXME FreeBSD: get_lock_info not implemented */ - return false; -} - -bool ctdb_get_blocker_pid(struct ctdb_lock_info *reqlock, pid_t *blocker_pid) -{ - /* FIXME FreeBSD: get_blocker_pid not implemented */ - return false; -} diff --git a/ctdb/common/system_gnu.c b/ctdb/common/system_gnu.c index 2ab13996132..bf8f43c4868 100644 --- a/ctdb/common/system_gnu.c +++ b/ctdb/common/system_gnu.c @@ -363,26 +363,8 @@ int ctdb_get_peer_pid(const int fd, pid_t *peer_pid) return 1; } -char *ctdb_get_process_name(pid_t pid) -{ - /* FIXME GNU/Hurd: get_process_name not implemented */ - return NULL; -} - int ctdb_set_process_name(const char *name) { /* FIXME GNU/Hurd: set_process_name not implemented */ return -ENOSYS; } - -bool ctdb_get_lock_info(pid_t req_pid, struct ctdb_lock_info *lock_info) -{ - /* FIXME GNU/Hurd: get_lock_info not implemented */ - return false; -} - -bool ctdb_get_blocker_pid(struct ctdb_lock_info *reqlock, pid_t *blocker_pid) -{ - /* FIXME GNU/Hurd: get_blocker_pid not implemented */ - return false; -} diff --git a/ctdb/common/system_kfreebsd.c b/ctdb/common/system_kfreebsd.c index 41aa4d6d8d6..de7c8911c89 100644 --- a/ctdb/common/system_kfreebsd.c +++ b/ctdb/common/system_kfreebsd.c @@ -363,39 +363,8 @@ int ctdb_get_peer_pid(const int fd, pid_t *peer_pid) return 1; } -char *ctdb_get_process_name(pid_t pid) -{ - char path[32]; - char buf[PATH_MAX]; - char *ptr; - int n; - - snprintf(path, sizeof(path), "/proc/%d/exe", pid); - n = readlink(path, buf, sizeof(buf)); - if (n < 0) { - return NULL; - } - - /* Remove any extra fields */ - buf[n] = '\0'; - ptr = strtok(buf, " "); - return strdup(ptr); -} - int ctdb_set_process_name(const char *name) { /* FIXME kFreeBSD: set_process_name not implemented */ return -ENOSYS; } - -bool ctdb_get_lock_info(pid_t req_pid, struct ctdb_lock_info *lock_info) -{ - /* FIXME kFreeBSD: get_lock_info not implemented */ - return false; -} - -bool ctdb_get_blocker_pid(struct ctdb_lock_info *reqlock, pid_t *blocker_pid) -{ - /* FIXME kFreeBSD: get_blocker_pid not implemented */ - return false; -} diff --git a/ctdb/common/system_linux.c b/ctdb/common/system_linux.c index fdb8d127579..79d1a83ff10 100644 --- a/ctdb/common/system_linux.c +++ b/ctdb/common/system_linux.c @@ -597,28 +597,6 @@ int ctdb_get_peer_pid(const int fd, pid_t *peer_pid) return ret; } -/* - * Find the process name from process ID - */ -char *ctdb_get_process_name(pid_t pid) -{ - char path[32]; - char buf[PATH_MAX]; - char *ptr; - int n; - - snprintf(path, sizeof(path), "/proc/%d/exe", pid); - n = readlink(path, buf, sizeof(buf)-1); - if (n < 0) { - return NULL; - } - - /* Remove any extra fields */ - buf[n] = '\0'; - ptr = strtok(buf, " "); - return (ptr == NULL ? ptr : strdup(ptr)); -} - /* * Set process name */ @@ -630,158 +608,3 @@ int ctdb_set_process_name(const char *name) procname[15] = '\0'; return prctl(PR_SET_NAME, (unsigned long)procname, 0, 0, 0); } - -/* - * Parsing a line from /proc/locks, - */ -static bool parse_proc_locks_line(char *line, pid_t *pid, - struct ctdb_lock_info *curlock) -{ - char *ptr, *saveptr; - - /* output of /proc/locks - * - * lock assigned - * 1: POSIX ADVISORY WRITE 25945 fd:00:6424820 212 212 - * - * lock waiting - * 1: -> POSIX ADVISORY WRITE 25946 fd:00:6424820 212 212 - */ - - /* Id: */ - ptr = strtok_r(line, " ", &saveptr); - if (ptr == NULL) return false; - - /* -> */ - ptr = strtok_r(NULL, " ", &saveptr); - if (ptr == NULL) return false; - if (strcmp(ptr, "->") == 0) { - curlock->waiting = true; - ptr = strtok_r(NULL, " ", &saveptr); - } else { - curlock->waiting = false; - } - - /* POSIX */ - if (ptr == NULL || strcmp(ptr, "POSIX") != 0) { - return false; - } - - /* ADVISORY */ - ptr = strtok_r(NULL, " ", &saveptr); - if (ptr == NULL) return false; - - /* WRITE */ - ptr = strtok_r(NULL, " ", &saveptr); - if (ptr == NULL) return false; - if (strcmp(ptr, "READ") == 0) { - curlock->read_only = true; - } else if (strcmp(ptr, "WRITE") == 0) { - curlock->read_only = false; - } else { - return false; - } - - /* PID */ - ptr = strtok_r(NULL, " ", &saveptr); - if (ptr == NULL) return false; - *pid = atoi(ptr); - - /* MAJOR:MINOR:INODE */ - ptr = strtok_r(NULL, " :", &saveptr); - if (ptr == NULL) return false; - ptr = strtok_r(NULL, " :", &saveptr); - if (ptr == NULL) return false; - ptr = strtok_r(NULL, " :", &saveptr); - if (ptr == NULL) return false; - curlock->inode = atol(ptr); - - /* START OFFSET */ - ptr = strtok_r(NULL, " ", &saveptr); - if (ptr == NULL) return false; - curlock->start = atol(ptr); - - /* END OFFSET */ - ptr = strtok_r(NULL, " ", &saveptr); - if (ptr == NULL) return false; - if (strncmp(ptr, "EOF", 3) == 0) { - curlock->end = (off_t)-1; - } else { - curlock->end = atol(ptr); - } - - return true; -} - -/* - * Find information of lock being waited on for given process ID - */ -bool ctdb_get_lock_info(pid_t req_pid, struct ctdb_lock_info *lock_info) -{ - FILE *fp; - struct ctdb_lock_info curlock; - pid_t pid; - char buf[1024]; - bool status = false; - - if ((fp = fopen("/proc/locks", "r")) == NULL) { - DEBUG(DEBUG_ERR, ("Failed to read locks information")); - return false; - } - while (fgets(buf, sizeof(buf), fp) != NULL) { - if (! parse_proc_locks_line(buf, &pid, &curlock)) { - continue; - } - if (pid == req_pid && curlock.waiting) { - *lock_info = curlock; - status = true; - break; - } - } - fclose(fp); - - return status; -} - -/* - * Find process ID which holds an overlapping byte lock for required - * inode and byte range. - */ -bool ctdb_get_blocker_pid(struct ctdb_lock_info *reqlock, pid_t *blocker_pid) -{ - FILE *fp; - struct ctdb_lock_info curlock; - pid_t pid; - char buf[1024]; - bool status = false; - - if ((fp = fopen("/proc/locks", "r")) == NULL) { - DEBUG(DEBUG_ERR, ("Failed to read locks information")); - return false; - } - while (fgets(buf, sizeof(buf), fp) != NULL) { - if (! parse_proc_locks_line(buf, &pid, &curlock)) { - continue; - } - - if (curlock.waiting) { - continue; - } - - if (curlock.inode != reqlock->inode) { - continue; - } - - if (curlock.start > reqlock->end || - curlock.end < reqlock->start) { - /* Outside the required range */ - continue; - } - *blocker_pid = pid; - status = true; - break; - } - fclose(fp); - - return status; -} diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 4cb0fe6a101..c172909ac15 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -1136,10 +1136,7 @@ struct ctdb_lock_info { bool read_only; }; -char *ctdb_get_process_name(pid_t pid); int ctdb_set_process_name(const char *name); -bool ctdb_get_lock_info(pid_t req_pid, struct ctdb_lock_info *lock_info); -bool ctdb_get_blocker_pid(struct ctdb_lock_info *reqlock, pid_t *blocker_pid); typedef void (*client_async_callback)(struct ctdb_context *ctdb, uint32_t node_pnn, int32_t res, TDB_DATA outdata, void *callback_data); diff --git a/ctdb/tests/src/ctdb_porting_tests.c b/ctdb/tests/src/ctdb_porting_tests.c index e95c25d978a..a4dda1930d0 100644 --- a/ctdb/tests/src/ctdb_porting_tests.c +++ b/ctdb/tests/src/ctdb_porting_tests.c @@ -233,22 +233,6 @@ static int test_ctdb_get_peer_pid(void) return 0; } -static int test_ctdb_get_process_name(void) -{ - char *process_name = NULL; - globals.testcount++; - process_name = ctdb_get_process_name(globals.helper_pid); - if ((process_name == NULL) || !strcmp(process_name, "unknown")) { - DEBUG(DEBUG_CRIT,("Test failed: Invalid process name of %d: %s\n", globals.helper_pid, process_name)); - free(process_name); - return -1; - } - DEBUG(DEBUG_INFO,("Test OK: Name of PID=%d: %s\n", globals.helper_pid, process_name)); - globals.successcount++; - free(process_name); - return 0; -} - /* main program */ @@ -301,8 +285,6 @@ int main(int argc, const char *argv[]) /* FIXME: Test ctdb_sys_{open,close}_capture_socket, ctdb_sys_read_tcp_packet */ test_ctdb_sys_check_iface_exists(); test_ctdb_get_peer_pid(); - test_ctdb_get_process_name(); - /* FIXME: Test ctdb_get_lock_info, ctdb_get_blocker_pid*/ socket_server_close();