Merge lp:~dannf/ubuntu/saucy/procps/pwdx-fixes into lp:ubuntu/saucy/procps

Proposed by dann frazier
Status: Merged
Merge reported by: Adam Conrad
Merged at revision: not available
Proposed branch: lp:~dannf/ubuntu/saucy/procps/pwdx-fixes
Merge into: lp:ubuntu/saucy/procps
Diff against target: 398 lines (+332/-1)
8 files modified
.pc/applied-patches (+2/-0)
.pc/lp1213156-pwdx-pid-0/pwdx.c (+147/-0)
.pc/lp1213160-pwdx-locale-fail/pwdx.c (+147/-0)
debian/changelog (+7/-0)
debian/patches/lp1213156-pwdx-pid-0 (+13/-0)
debian/patches/lp1213160-pwdx-locale-fail (+12/-0)
debian/patches/series (+2/-0)
pwdx.c (+2/-1)
To merge this branch: bzr merge lp:~dannf/ubuntu/saucy/procps/pwdx-fixes
Reviewer Review Type Date Requested Status
Ubuntu branches Pending
Review via email: mp+180606@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.pc/applied-patches'
--- .pc/applied-patches 2012-06-20 13:12:40 +0000
+++ .pc/applied-patches 2013-08-16 16:17:41 +0000
@@ -2,3 +2,5 @@
2bts676239-pkill-u-option2bts676239-pkill-u-option
3watch_8bit3watch_8bit
4uptime_test4uptime_test
5lp1213156-pwdx-pid-0
6lp1213160-pwdx-locale-fail
57
=== added directory '.pc/lp1213156-pwdx-pid-0'
=== added file '.pc/lp1213156-pwdx-pid-0/.timestamp'
=== added file '.pc/lp1213156-pwdx-pid-0/pwdx.c'
--- .pc/lp1213156-pwdx-pid-0/pwdx.c 1970-01-01 00:00:00 +0000
+++ .pc/lp1213156-pwdx-pid-0/pwdx.c 2013-08-16 16:17:41 +0000
@@ -0,0 +1,147 @@
1/*
2 * pwdx.c - print process working directory
3 * Copyright 2004 Nicholas Miell
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <errno.h>
21#include <getopt.h>
22#include <limits.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <sys/types.h>
27#include <unistd.h>
28
29#include "proc/version.h"
30#include "c.h"
31#include "nls.h"
32#include "xalloc.h"
33#include "fileutils.h"
34
35static void __attribute__ ((__noreturn__)) usage(FILE * out)
36{
37 fputs(USAGE_HEADER, out);
38 fprintf(out, _(" %s [options] pid...\n"), program_invocation_short_name);
39 fputs(USAGE_OPTIONS, out);
40 fputs(USAGE_HELP, out);
41 fputs(USAGE_VERSION, out);
42 fprintf(out, USAGE_MAN_TAIL("pwdx(1)"));
43
44 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
45}
46
47int check_pid_argument(char *input)
48{
49 int skip = 0;
50 long pid;
51 char *end = NULL;
52
53 if (!strncmp("/proc/", input, 6))
54 skip = 6;
55 pid = strtol(input + skip, &end, 10);
56
57 if (errno || input + skip == end || (end && *end))
58 return 1;
59 if (pid < 1)
60 return 1;
61 return 0;
62}
63
64int main(int argc, char *argv[])
65{
66 char ch;
67 int retval = 0, i;
68 int alloclen = 128;
69 char *pathbuf;
70
71 static const struct option longopts[] = {
72 {"version", no_argument, 0, 'V'},
73 {"help", no_argument, 0, 'h'},
74 {NULL, 0, 0, 0}
75 };
76
77 program_invocation_name = program_invocation_short_name;
78 setlocale (LC_ALL, "");
79 bindtextdomain(PACKAGE, LOCALEDIR);
80 textdomain(PACKAGE);
81 atexit(close_stdout);
82
83 while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
84 switch (ch) {
85 case 'V':
86 printf(PROCPS_NG_VERSION);
87 return EXIT_SUCCESS;
88 case 'h':
89 usage(stdout);
90 default:
91 usage(stderr);
92 }
93
94 argc -= optind;
95 argv += optind;
96
97 if (argc == 0)
98 usage(stderr);
99
100 pathbuf = malloc(alloclen);
101
102 for (i = 0; i < argc; i++) {
103 char *s;
104 ssize_t len, buflen;
105 /* Constant 10 is the length of strings "/proc/" + "/cwd" + 1 */
106 char *buf;
107 buflen = 10 + strlen(argv[i]) + 1;
108 buf = xmalloc(buflen);
109
110 if (check_pid_argument(argv[i]))
111 xerrx(EXIT_FAILURE, _("invalid process id: %s"),
112 argv[i]);
113 /*
114 * At this point, all arguments are in the form
115 * /proc/NNNN or NNNN, so a simple check based on
116 * the first char is possible
117 */
118 if (argv[i][0] != '/')
119 snprintf(buf, buflen, "/proc/%s/cwd", argv[i]);
120 else
121 snprintf(buf, buflen, "%s/cwd", argv[i]);
122
123 /*
124 * buf contains /proc/NNNN/cwd symlink name
125 * on entry, the target of that symlink on return
126 */
127 while ((len = readlink(buf, pathbuf, alloclen)) == alloclen) {
128 alloclen *= 2;
129 pathbuf = realloc(pathbuf, alloclen);
130 }
131 free(buf);
132
133 if (len < 0) {
134 s = strerror(errno == ENOENT ? ESRCH : errno);
135 retval = EXIT_FAILURE;
136 fprintf(stderr, "%s: %s\n", argv[i], s);
137 continue;
138 } else {
139 pathbuf[len] = 0;
140 s = pathbuf;
141 }
142
143 printf("%s: %s\n", argv[i], s);
144 }
145 free(pathbuf);
146 return retval;
147}
0148
=== added directory '.pc/lp1213160-pwdx-locale-fail'
=== added file '.pc/lp1213160-pwdx-locale-fail/.timestamp'
=== added file '.pc/lp1213160-pwdx-locale-fail/pwdx.c'
--- .pc/lp1213160-pwdx-locale-fail/pwdx.c 1970-01-01 00:00:00 +0000
+++ .pc/lp1213160-pwdx-locale-fail/pwdx.c 2013-08-16 16:17:41 +0000
@@ -0,0 +1,147 @@
1/*
2 * pwdx.c - print process working directory
3 * Copyright 2004 Nicholas Miell
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <errno.h>
21#include <getopt.h>
22#include <limits.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <sys/types.h>
27#include <unistd.h>
28
29#include "proc/version.h"
30#include "c.h"
31#include "nls.h"
32#include "xalloc.h"
33#include "fileutils.h"
34
35static void __attribute__ ((__noreturn__)) usage(FILE * out)
36{
37 fputs(USAGE_HEADER, out);
38 fprintf(out, _(" %s [options] pid...\n"), program_invocation_short_name);
39 fputs(USAGE_OPTIONS, out);
40 fputs(USAGE_HELP, out);
41 fputs(USAGE_VERSION, out);
42 fprintf(out, USAGE_MAN_TAIL("pwdx(1)"));
43
44 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
45}
46
47int check_pid_argument(char *input)
48{
49 int skip = 0;
50 long pid;
51 char *end = NULL;
52
53 if (!strncmp("/proc/", input, 6))
54 skip = 6;
55 pid = strtol(input + skip, &end, 10);
56
57 if (errno || input + skip == end || (end && *end))
58 return 1;
59 if (pid < 1)
60 return 1;
61 return 0;
62}
63
64int main(int argc, char *argv[])
65{
66 int ch;
67 int retval = 0, i;
68 int alloclen = 128;
69 char *pathbuf;
70
71 static const struct option longopts[] = {
72 {"version", no_argument, 0, 'V'},
73 {"help", no_argument, 0, 'h'},
74 {NULL, 0, 0, 0}
75 };
76
77 program_invocation_name = program_invocation_short_name;
78 setlocale (LC_ALL, "");
79 bindtextdomain(PACKAGE, LOCALEDIR);
80 textdomain(PACKAGE);
81 atexit(close_stdout);
82
83 while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
84 switch (ch) {
85 case 'V':
86 printf(PROCPS_NG_VERSION);
87 return EXIT_SUCCESS;
88 case 'h':
89 usage(stdout);
90 default:
91 usage(stderr);
92 }
93
94 argc -= optind;
95 argv += optind;
96
97 if (argc == 0)
98 usage(stderr);
99
100 pathbuf = malloc(alloclen);
101
102 for (i = 0; i < argc; i++) {
103 char *s;
104 ssize_t len, buflen;
105 /* Constant 10 is the length of strings "/proc/" + "/cwd" + 1 */
106 char *buf;
107 buflen = 10 + strlen(argv[i]) + 1;
108 buf = xmalloc(buflen);
109
110 if (check_pid_argument(argv[i]))
111 xerrx(EXIT_FAILURE, _("invalid process id: %s"),
112 argv[i]);
113 /*
114 * At this point, all arguments are in the form
115 * /proc/NNNN or NNNN, so a simple check based on
116 * the first char is possible
117 */
118 if (argv[i][0] != '/')
119 snprintf(buf, buflen, "/proc/%s/cwd", argv[i]);
120 else
121 snprintf(buf, buflen, "%s/cwd", argv[i]);
122
123 /*
124 * buf contains /proc/NNNN/cwd symlink name
125 * on entry, the target of that symlink on return
126 */
127 while ((len = readlink(buf, pathbuf, alloclen)) == alloclen) {
128 alloclen *= 2;
129 pathbuf = realloc(pathbuf, alloclen);
130 }
131 free(buf);
132
133 if (len < 0) {
134 s = strerror(errno == ENOENT ? ESRCH : errno);
135 retval = EXIT_FAILURE;
136 fprintf(stderr, "%s: %s\n", argv[i], s);
137 continue;
138 } else {
139 pathbuf[len] = 0;
140 s = pathbuf;
141 }
142
143 printf("%s: %s\n", argv[i], s);
144 }
145 free(pathbuf);
146 return retval;
147}
0148
=== modified file 'debian/changelog'
--- debian/changelog 2013-01-04 17:13:35 +0000
+++ debian/changelog 2013-08-16 16:17:41 +0000
@@ -1,3 +1,10 @@
1procps (1:3.3.3-2ubuntu6) UNRELEASED; urgency=low
2
3 * pwdx.c: Fix pwdx argument parsing, fixing FTBFS on arm64 (LP: #1213156)
4 * pwdx.c: Fix failure when executed in a nonexistent locale (LP: #1213160)
5
6 -- dann frazier <dann.frazier@canonical.com> Fri, 16 Aug 2013 10:07:49 -0600
7
1procps (1:3.3.3-2ubuntu5) raring; urgency=low8procps (1:3.3.3-2ubuntu5) raring; urgency=low
29
3 * Fix cross build.10 * Fix cross build.
411
=== added file 'debian/patches/lp1213156-pwdx-pid-0'
--- debian/patches/lp1213156-pwdx-pid-0 1970-01-01 00:00:00 +0000
+++ debian/patches/lp1213156-pwdx-pid-0 2013-08-16 16:17:41 +0000
@@ -0,0 +1,13 @@
1Index: procps/pwdx.c
2===================================================================
3--- procps.orig/pwdx.c 2013-08-16 09:26:26.606789000 -0600
4+++ procps/pwdx.c 2013-08-16 10:06:49.070216686 -0600
5@@ -63,7 +63,7 @@
6
7 int main(int argc, char *argv[])
8 {
9- char ch;
10+ int ch;
11 int retval = 0, i;
12 int alloclen = 128;
13 char *pathbuf;
014
=== added file 'debian/patches/lp1213160-pwdx-locale-fail'
--- debian/patches/lp1213160-pwdx-locale-fail 1970-01-01 00:00:00 +0000
+++ debian/patches/lp1213160-pwdx-locale-fail 2013-08-16 16:17:41 +0000
@@ -0,0 +1,12 @@
1Index: procps/pwdx.c
2===================================================================
3--- procps.orig/pwdx.c 2013-08-16 10:13:41.723121575 -0600
4+++ procps/pwdx.c 2013-08-16 10:13:47.619192217 -0600
5@@ -52,6 +52,7 @@
6
7 if (!strncmp("/proc/", input, 6))
8 skip = 6;
9+ errno = 0;
10 pid = strtol(input + skip, &end, 10);
11
12 if (errno || input + skip == end || (end && *end))
013
=== modified file 'debian/patches/series'
--- debian/patches/series 2012-06-20 13:12:40 +0000
+++ debian/patches/series 2013-08-16 16:17:41 +0000
@@ -2,3 +2,5 @@
2bts676239-pkill-u-option2bts676239-pkill-u-option
3watch_8bit3watch_8bit
4uptime_test4uptime_test
5lp1213156-pwdx-pid-0
6lp1213160-pwdx-locale-fail
57
=== modified file 'pwdx.c'
--- pwdx.c 2012-05-20 16:48:44 +0000
+++ pwdx.c 2013-08-16 16:17:41 +0000
@@ -52,6 +52,7 @@
5252
53 if (!strncmp("/proc/", input, 6))53 if (!strncmp("/proc/", input, 6))
54 skip = 6;54 skip = 6;
55 errno = 0;
55 pid = strtol(input + skip, &end, 10);56 pid = strtol(input + skip, &end, 10);
5657
57 if (errno || input + skip == end || (end && *end))58 if (errno || input + skip == end || (end && *end))
@@ -63,7 +64,7 @@
6364
64int main(int argc, char *argv[])65int main(int argc, char *argv[])
65{66{
66 char ch;67 int ch;
67 int retval = 0, i;68 int retval = 0, i;
68 int alloclen = 128;69 int alloclen = 128;
69 char *pathbuf;70 char *pathbuf;

Subscribers

People subscribed via source and target branches

to all changes: