static int
usage ()
{
- fprintf(stderr,
+ fprintf(stderr,
"Usage: pslog PID...\n"
" pslog -V, --version\n\n"
return 1;
}
+ ssize_t linkname_size;
char buf[PATH_MAX+1];
DIR *pid_dir;
while((namelist = readdir(pid_dir))) {
strncpy(linkpath, fullpath, PATH_MAX);
strncat(linkpath, namelist->d_name, PATH_MAX - strlen(linkpath));
- readlink(linkpath, buf, PATH_MAX -1);
+ linkname_size = readlink(linkpath, buf, PATH_MAX -1);
+ buf[linkname_size+1] = '\0';
if (regexec(&re_log, buf, 0, NULL, 0) == 0) {
fprintf(stdout, "Log path: %s\n", buf);
free(linkpath);
free(fullpath);
regfree(&re_log);
+
+ if (closedir(pid_dir)) {
+ perror ("closedir");
+ return 1;
+ }
+
return 0;
}