MCPcopy Create free account
hub / github.com/git/git / stat_parent_pid

Function stat_parent_pid

compat/linux/procinfo.c:92–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92static int stat_parent_pid(pid_t pid, struct strbuf *name, int *statppid)
93{
94 struct strbuf procfs_path = STRBUF_INIT;
95 struct strbuf sb = STRBUF_INIT;
96 FILE *fp;
97 int ret = -1;
98
99 /* try to use procfs if it's present. */
100 strbuf_addf(&procfs_path, "/proc/%d/stat", pid);
101 fp = fopen(procfs_path.buf, "r");
102 if (!fp)
103 goto cleanup;
104
105 /*
106 * We could be more strict here and assert that we read at
107 * least STAT_PARENT_PID_READ_N. My reading of procfs(5) is
108 * that on any modern kernel (at least since 2.6.0 released in
109 * 2003) even if all the mandatory numeric fields were zero'd
110 * out we'd get at least 100 bytes, but let's just check that
111 * we got anything at all and trust the parse_proc_stat()
112 * function to handle its "Bad Kernel?" error checking.
113 */
114 if (!strbuf_fread(&sb, STAT_PARENT_PID_READ_N, fp))
115 goto cleanup;
116 if (parse_proc_stat(&sb, name, statppid) < 0)
117 goto cleanup;
118
119 ret = 0;
120cleanup:
121 if (fp)
122 fclose(fp);
123 strbuf_release(&procfs_path);
124 strbuf_release(&sb);
125
126 return ret;
127}
128
129static void push_ancestry_name(struct strvec *names, pid_t pid)
130{

Callers 1

push_ancestry_nameFunction · 0.85

Calls 4

strbuf_addfFunction · 0.85
strbuf_freadFunction · 0.85
parse_proc_statFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected