aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-11 13:57:08 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-11 13:57:08 +0000
commit0e52541917a80a4c5aee9d32fcc81cf9967f2aed (patch)
tree26351601d9b046a8834e9a462dc261c21877de9a
parent88643a86d07f31779b96f0beef23050b951e2fd1 (diff)
downloadbusybox-w32-0e52541917a80a4c5aee9d32fcc81cf9967f2aed.tar.gz
busybox-w32-0e52541917a80a4c5aee9d32fcc81cf9967f2aed.tar.bz2
busybox-w32-0e52541917a80a4c5aee9d32fcc81cf9967f2aed.zip
taskset: fix some careless code in both fancy and non-fancy cases.
-5 bytes for fancy, +5 for non-fancy
-rw-r--r--libbb/mode_string.c4
-rw-r--r--miscutils/last.c2
-rw-r--r--miscutils/taskset.c48
3 files changed, 39 insertions, 15 deletions
diff --git a/libbb/mode_string.c b/libbb/mode_string.c
index b9975f4cc..7d4e514b1 100644
--- a/libbb/mode_string.c
+++ b/libbb/mode_string.c
@@ -48,7 +48,7 @@ static const mode_t mode_flags[] = {
48/* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C', 48/* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C',
49 * and 'B' types don't appear to be available on linux. So I removed them. */ 49 * and 'B' types don't appear to be available on linux. So I removed them. */
50static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???"; 50static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???";
51/* 0123456789abcdef */ 51/***************************************** 0123456789abcdef */
52static const char mode_chars[7] ALIGN1 = "rwxSTst"; 52static const char mode_chars[7] ALIGN1 = "rwxSTst";
53 53
54const char* FAST_FUNC bb_mode_string(mode_t mode) 54const char* FAST_FUNC bb_mode_string(mode_t mode)
@@ -88,7 +88,7 @@ const char* FAST_FUNC bb_mode_string(mode_t mode)
88/* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C', 88/* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C',
89 * and 'B' types don't appear to be available on linux. So I removed them. */ 89 * and 'B' types don't appear to be available on linux. So I removed them. */
90static const char type_chars[16] = "?pc?d?b?-?l?s???"; 90static const char type_chars[16] = "?pc?d?b?-?l?s???";
91/* 0123456789abcdef */ 91/********************************** 0123456789abcdef */
92static const char mode_chars[7] = "rwxSTst"; 92static const char mode_chars[7] = "rwxSTst";
93 93
94const char* FAST_FUNC bb_mode_string(mode_t mode) 94const char* FAST_FUNC bb_mode_string(mode_t mode)
diff --git a/miscutils/last.c b/miscutils/last.c
index 8c8192bee..f8c301395 100644
--- a/miscutils/last.c
+++ b/miscutils/last.c
@@ -117,6 +117,8 @@ int last_main(int argc, char **argv UNUSED_PARAM)
117 strcpy(ut.ut_line, "system boot"); 117 strcpy(ut.ut_line, "system boot");
118 } 118 }
119 } 119 }
120 /* manpages say ut_tv.tv_sec *is* time_t,
121 * but some systems have it wrong */
120 t_tmp = (time_t)ut.ut_tv.tv_sec; 122 t_tmp = (time_t)ut.ut_tv.tv_sec;
121 printf("%-10s %-14s %-18s %-12.12s\n", 123 printf("%-10s %-14s %-18s %-12.12s\n",
122 ut.ut_user, ut.ut_line, ut.ut_host, ctime(&t_tmp) + 4); 124 ut.ut_user, ut.ut_line, ut.ut_host, ctime(&t_tmp) + 4);
diff --git a/miscutils/taskset.c b/miscutils/taskset.c
index 3175af10d..b43d42e90 100644
--- a/miscutils/taskset.c
+++ b/miscutils/taskset.c
@@ -11,31 +11,53 @@
11 11
12#if ENABLE_FEATURE_TASKSET_FANCY 12#if ENABLE_FEATURE_TASKSET_FANCY
13#define TASKSET_PRINTF_MASK "%s" 13#define TASKSET_PRINTF_MASK "%s"
14#define from_cpuset(x) __from_cpuset(&x)
15/* craft a string from the mask */ 14/* craft a string from the mask */
16static char *__from_cpuset(cpu_set_t *mask) 15static char *from_cpuset(cpu_set_t *mask)
17{ 16{
18 int i; 17 int i;
19 char *ret = 0, *str = xzalloc(9); 18 char *ret = NULL;
19 char *str = xzalloc((CPU_SETSIZE / 4) + 1); /* we will leak it */
20 20
21 for (i = CPU_SETSIZE - 4; i >= 0; i -= 4) { 21 for (i = CPU_SETSIZE - 4; i >= 0; i -= 4) {
22 char val = 0; 22 int val = 0;
23 int off; 23 int off;
24 for (off = 0; off <= 3; ++off) 24 for (off = 0; off <= 3; ++off)
25 if (CPU_ISSET(i+off, mask)) 25 if (CPU_ISSET(i + off, mask))
26 val |= 1<<off; 26 val |= 1 << off;
27
28 if (!ret && val) 27 if (!ret && val)
29 ret = str; 28 ret = str;
30 *str++ = (val-'0'<=9) ? (val+48) : (val+87); 29 *str++ = bb_hexdigits_upcase[val] | 0x20;
31 } 30 }
32 return ret; 31 return ret;
33} 32}
34#else 33#else
35#define TASKSET_PRINTF_MASK "%x" 34#define TASKSET_PRINTF_MASK "%llx"
36/* (void*) cast is for battling gcc: */ 35static unsigned long long from_cpuset(cpu_set_t *mask)
37/* "dereferencing type-punned pointer will break strict-aliasing rules" */ 36{
38#define from_cpuset(mask) (*(unsigned*)(void*)&(mask)) 37 struct BUG_CPU_SETSIZE_is_too_small {
38 char BUG_CPU_SETSIZE_is_too_small[
39 CPU_SETSIZE < sizeof(int) ? -1 : 1];
40 };
41 char *p = (void*)mask;
42
43 /* Take the least significant bits. Careful!
44 * Consider both CPU_SETSIZE=4 and CPU_SETSIZE=1024 cases
45 */
46#if BB_BIG_ENDIAN
47 /* For big endian, it means LAST bits */
48 if (CPU_SETSIZE < sizeof(long))
49 p += CPU_SETSIZE - sizeof(int);
50 else if (CPU_SETSIZE < sizeof(long long))
51 p += CPU_SETSIZE - sizeof(long);
52 else
53 p += CPU_SETSIZE - sizeof(long long);
54#endif
55 if (CPU_SETSIZE < sizeof(long))
56 return *(unsigned*)p;
57 if (CPU_SETSIZE < sizeof(long long))
58 return *(unsigned long*)p;
59 return *(unsigned long long*)p;
60}
39#endif 61#endif
40 62
41 63
@@ -78,7 +100,7 @@ int taskset_main(int argc UNUSED_PARAM, char **argv)
78 if (sched_getaffinity(pid, sizeof(mask), &mask) < 0) 100 if (sched_getaffinity(pid, sizeof(mask), &mask) < 0)
79 bb_perror_msg_and_die("can't %cet pid %d's affinity", 'g', pid); 101 bb_perror_msg_and_die("can't %cet pid %d's affinity", 'g', pid);
80 printf("pid %d's %s affinity mask: "TASKSET_PRINTF_MASK"\n", 102 printf("pid %d's %s affinity mask: "TASKSET_PRINTF_MASK"\n",
81 pid, current_new, from_cpuset(mask)); 103 pid, current_new, from_cpuset(&mask));
82 if (!*argv) { 104 if (!*argv) {
83 /* Either it was just "-p <pid>", 105 /* Either it was just "-p <pid>",
84 * or it was "-p <aff> <pid>" and we came here 106 * or it was "-p <aff> <pid>" and we came here