瀏覽代碼

s-s-d: Use a new xstrdup that never returns NULL instead of strdup

Guillem Jover 17 年之前
父節點
當前提交
25d4a1752f
共有 2 個文件被更改,包括 17 次插入1 次删除
  1. 5 0
      ChangeLog
  2. 12 1
      utils/start-stop-daemon.c

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+2009-01-14  Guillem Jover  <guillem@debian.org>
+
+	* utils/start-stop-daemon.c (xstrdup): New function.
+	(parse_options): Use xstrdup instead of strdup.
+
 2009-01-10  Guillem Jover  <guillem@debian.org>
 
 	* utils/start-stop-daemon.c (main): If changeuser is a uid, call

+ 12 - 1
utils/start-stop-daemon.c

@@ -199,6 +199,17 @@ xmalloc(int size)
 	fatal("malloc(%d) failed", size);
 }
 
+static char *
+xstrdup(const char *str)
+{
+	char *new_str;
+
+	new_str = strdup(str);
+	if (new_str)
+		return new_str;
+	fatal("strdup(%s) failed", str);
+}
+
 static void
 xgettimeofday(struct timeval *tv)
 {
@@ -584,7 +595,7 @@ parse_options(int argc, char * const *argv)
 		case 'c':  /* --chuid <username>|<uid> */
 			/* we copy the string just in case we need the
 			 * argument later. */
-			changeuser = strdup(optarg);
+			changeuser = xstrdup(optarg);
 			changeuser = strtok(changeuser, ":");
 			changegroup = strtok(NULL, ":");
 			break;