From nobody Wed Jun 10 12:36:02 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gb4yJ3Y2Dz6g45L for ; Wed, 10 Jun 2026 12:36:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gb4yJ1C6Mz42v9 for ; Wed, 10 Jun 2026 12:36:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1781094968; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=87zNTx+DOupLS/dm+oSqepGT5wJe4sV8JvjwKigjoss=; b=o8Nu+h3OlZ3wY+sQKLDGj7t7n2rDLXixzKOZ3U+JdaXuBipvMdNOK7+lvPcIpJ32J0Gr1H 4jD8wNjVsk1Mbp+dvypkfFi1iB/4UV2ehr1PRo/UkCLpxILodcH16nOjgwVBh9I32prqto WpdM6vyDMiVQbgV4d61aEoKyVYalem2U7uEaiVFxY/zZw04cCSQoo4NAnW/EOx95SS3+JA xy9yeoSpWJ4ORzTINhk7eZvIObCjFVMHP0CYn8/sOKH8iUraeyJa2we2VuK4WW68o6ID86 nB5NNrvzG69hVbneHCxYMjZGFjByV5scj767tA2WpDBO9e4PQjF6ngAs7gThVg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1781094968; a=rsa-sha256; cv=none; b=bZluRqd217gz4HY6XgSCBhdZTD7mcnkfdMwY5ASiE7uFdOqr+UopQikVL6vYRvMAhhNmbF GqPLS3PWlaIF/W/fE1wpc6XCKet2exdgs1u+qmI73IJ2SbZJgjJHEKfvdK3RehcaR2jvE+ KixeQ7+UAoMgo93ljYOQhVQwG6wLKP3HkjkKyrguJuHMAWpOFaTlndcPU5cjD6afv3xWo5 lVU3clQY37EZ9mBrJKTYcUxpIUKp2OV2Z3dGHTcNJz9ZhrZNwXPyLkjkHz3OkRdW0kf6Fn dO7ikevt+lAT1MFflB+5qnynYPctr3NGGAeCv9vupz+rkdFBpM6uP7pdPPpf/g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1781094968; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=87zNTx+DOupLS/dm+oSqepGT5wJe4sV8JvjwKigjoss=; b=uR1JI0q2ID/8BCBtFF0TegTa+7a6UMYzXLD4Jiw10VEIPAfzco3A5OY50hlmEm8kFlw7gf 1qK4PZg5GFMasBGFP/Bptvnu2x4Ohf2g9L3DYqBMlsEXkWRBXHLG2SbSov+uNnOMWey0A5 Z7M1rwE59EDmweYU3HTxbp7dceZuvDjtDnV/6J9BrRuatrJ/4HMQ7Xz1ybQG0PJszRzv73 yPTGrh4dy3pdnBdwHmDCKSdWAPtFr8zA2vFZqVfeYR1gfhk9TIkHvbniYHTdwz3yB0Ffqc BEu6vUMUeg25slW8nQ3u/yQqWDdE1dXuTzlqL2k842tbY4tHyY8fly2cruzeDQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gb4yJ0bvgz1Kdk for ; Wed, 10 Jun 2026 12:36:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3e002 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 10 Jun 2026 12:36:02 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: androvonx95 From: Warner Losh Subject: git: 925f53682469 - main - improve renice user error messages List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 925f53682469ea12c017b48114b16e8f1627fb0b Auto-Submitted: auto-generated Date: Wed, 10 Jun 2026 12:36:02 +0000 Message-Id: <6a295a32.3e002.31d3fa83@gitrepo.freebsd.org> The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=925f53682469ea12c017b48114b16e8f1627fb0b commit 925f53682469ea12c017b48114b16e8f1627fb0b Author: androvonx95 AuthorDate: 2025-07-15 18:01:28 +0000 Commit: Warner Losh CommitDate: 2026-06-10 12:35:02 +0000 improve renice user error messages Improve error handling for invalid user names and UIDs in renice: - Use warnx() and err() for consistent error reporting - Set errno = EINVAL for invalid input - Provide clearer error messages for invalid user names and UIDs - Add test cases for invalid user input Signed-off-by: androvonx95 Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1768 --- usr.bin/renice/renice.c | 31 +++++++++++++++++--- usr.bin/renice/tests/renice_test.sh | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/usr.bin/renice/renice.c b/usr.bin/renice/renice.c index 4931a39c0f67..240ddf54134c 100644 --- a/usr.bin/renice/renice.c +++ b/usr.bin/renice/renice.c @@ -97,6 +97,7 @@ main(int argc, char *argv[]) if ((pwd = getpwnam(*argv)) != NULL) who = pwd->pw_uid; else if (getnum("uid", *argv, &who)) { + warnx("invalid uid: %s", *argv); errs++; continue; } else if (who < 0) { @@ -106,6 +107,7 @@ main(int argc, char *argv[]) } } else { if (getnum("pid", *argv, &who)) { + warnx("invalid pid: %s", *argv); errs++; continue; } @@ -126,11 +128,27 @@ static int donice(int which, int who, int prio, bool incr) { int oldprio; + const char *who_type; + + switch (which) { + case PRIO_PROCESS: + who_type = "process"; + break; + case PRIO_PGRP: + who_type = "process group"; + break; + case PRIO_USER: + who_type = "user"; + break; + default: + who_type = "unknown"; + break; + } errno = 0; oldprio = getpriority(which, who); if (oldprio == -1 && errno) { - warn("%d: getpriority", who); + warnx("%s %d: getpriority failed", who_type, who); return (1); } if (incr) @@ -140,11 +158,16 @@ donice(int which, int who, int prio, bool incr) if (prio < PRIO_MIN) prio = PRIO_MIN; if (setpriority(which, who, prio) < 0) { - warn("%d: setpriority", who); + if (errno == EPERM) { + warnx("Permission denied: cannot set priority for %s %d", + who_type, who); + return (1); + } + warnx("%s %d: setpriority failed", who_type, who); return (1); } - fprintf(stderr, "%d: old priority %d, new priority %d\n", who, - oldprio, prio); + fprintf(stderr, "%s %d: old priority %d, new priority %d\n", who_type, + who, oldprio, prio); return (0); } diff --git a/usr.bin/renice/tests/renice_test.sh b/usr.bin/renice/tests/renice_test.sh index 7983eb594716..116f1be60fe9 100755 --- a/usr.bin/renice/tests/renice_test.sh +++ b/usr.bin/renice/tests/renice_test.sh @@ -51,6 +51,50 @@ renice_rel_pid_body() { kill $pid } +atf_test_case renice_invalid_priority +renice_invalid_priority_head() { + atf_set "descr" "Verify handling of invalid priority values" +} +renice_invalid_priority_body() { + local pid + sleep 60 & + pid=$! + + # Test out of range priority + atf_check -s exit:1 -e match:"numeric value out of range" renice 100000 $pid + atf_check -s exit:1 -e match:"numeric value out of range" renice -100000 $pid + + # Test invalid priority format + atf_check -s exit:1 -e match:"invalid numeric value" renice "abc" $pid + atf_check -s exit:1 -e match:"invalid numeric value" renice "12.3" $pid + + kill $pid +} + +atf_test_case renice_permission_denied +renice_permission_denied_head() { + atf_set "descr" "Verify handling of permission denied cases" +} +renice_permission_denied_body() { + local pid + sleep 60 & + pid=$! + + # Test permission denied with non-root user + atf_check -s exit:1 -e match:"Permission denied: cannot set priority" renice -n 10 $pid + + kill $pid +} + +atf_test_case renice_nonexistent_process +renice_nonexistent_process_head() { + atf_set "descr" "Verify handling of non-existent process" +} +renice_nonexistent_process_body() { + # Test with a non-existent PID + atf_check -s exit:1 -e match:"process 999999 not found" renice 10 999999 +} + atf_test_case renice_abs_pgid renice_abs_pgid_head() { atf_set "descr" "Set a process group's nice number to an absolute value" @@ -115,6 +159,18 @@ renice_rel_user_body() { kill $pid } +atf_test_case renice_invalid_user +renice_invalid_user_head() { + atf_set "descr" "Verify handling of invalid user names" +} +renice_invalid_user_body() { + # Test with non-existent user name + atf_check -s exit:1 -e match:"Invalid user name or UID: nonexist" renice 10 -u nonexist + + # Test with invalid UID + atf_check -s exit:1 -e match:"Invalid UID: -1" renice 10 -u -1 +} + atf_test_case renice_delim renice_delim_head() { atf_set "descr" "Test various delimiter positions" @@ -169,6 +225,7 @@ atf_init_test_cases() { atf_add_test_case renice_rel_pgid atf_add_test_case renice_abs_user atf_add_test_case renice_rel_user + atf_add_test_case renice_invalid_user atf_add_test_case renice_delim atf_add_test_case renice_incr_noarg }