From nobody Sun Sep 1 08:56:53 2024 X-Original-To: bugs@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 4WxQjy143vz5Tr2D for ; Sun, 01 Sep 2024 08:56:54 +0000 (UTC) (envelope-from bugzilla-noreply@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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WxQjx729Jz4vCn for ; Sun, 1 Sep 2024 08:56:53 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725181014; a=rsa-sha256; cv=none; b=M5i9skYx3GmjJKaSXT2qRa+7TddUaKA0KD62BzSNQjamYe279yESSYTiS1m/zgJO3rM8nw Ibq2JoSG3p4j4XvU9U6pV3n3ymhUbNZbgMql9ra1gpBSlthKw2dMVZCltxSAGeUqARNtwj KJK90rDYlQZqv9oZA0sEl6OdBg2yJyKbdXMMYIpmUTNSr1vBjBbX+KjAr1FachLzyLgq7s b9SEIPQucATB97EQFzpWARSYH1U3Sw1l38/AUDScXYCFOOtiOrz1V7si2O+t8HjsNI4Og6 fr4TIbg3rFC+DRg6/qHfGi3w1zi1kpf4wi39nX6oPPQKMhWOwP0QFW3jLAbVIw== 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=1725181014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4ZWuodWO+4BDaU2i/vzEBAEMvb1MSnCRH0Krh3ZTkz8=; b=v2tloAOYwdHBu5vZEXh1IafSndq8J8XxCjyWnsIBnxHxtk5tvmeZxvBblxOEQVvJVRvtnm KHPZG3ALPpV2zh1qmy2MpUQvWt+cj2ssbXysxjHHDle1bLEdTnK5A6rI7/rd6WThssbXcY dZvjqnkQ3j/sJjEu/KrhufxFFVtP6Ytu9bTxe0nhksqFC3xBqpYFVX/0CW6tKr/BCssnik B0Y3PQ/BgRPK8y2wKbw5y8K6qT6w1fW4UIyuhH+/meWgbmgGvWUYomABTOcZDakkYr669V SNEbIFjBhE4k/0jyuIYajz+ij1ZWrkDEyYeHiKodV5CBREaMp5hjMabylSYSWQ== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WxQjx6WnRzMdG for ; Sun, 1 Sep 2024 08:56:53 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 4818urxR091231 for ; Sun, 1 Sep 2024 08:56:53 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 4818ur44091230 for bugs@FreeBSD.org; Sun, 1 Sep 2024 08:56:53 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 268436] [libc] syslog() and vsyslog() do not preserve the errno at the time of the call. Date: Sun, 01 Sep 2024 08:56:53 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: Unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Many People X-Bugzilla-Who: hodong@nimfsoft.art X-Bugzilla-Status: Open X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@FreeBSD.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D268436 --- Comment #4 from Hodong --- #include #include #include #include #include #include void* c_realloc (void* ptr, size_t size) { if (!size) { free (ptr); return NULL; } void* mem =3D realloc (ptr, size); if (mem) return mem; perror (__PRETTY_FUNCTION__); abort (); } char* c_str_join (const char *str, ...) { va_list ap; size_t offset =3D 0; char* result =3D NULL; va_start (ap, str); for (const char* s =3D str; s !=3D NULL; s =3D va_arg (ap, const char*)) { size_t len =3D strlen (s); result =3D c_realloc (result, offset + len + 1); memcpy (result + offset, s, len); offset =3D offset + len; } va_end (ap); if (result) result[offset] =3D '\0'; return result; } void c_log (int priority, const char* format, ...) { const char* prefix; char* new_format; va_list args; switch (priority) { case LOG_EMERG: prefix =3D "EMERGENCY"; break; case LOG_ALERT: prefix =3D "ALERT"; break; case LOG_CRIT: prefix =3D "CRITICAL"; break; case LOG_ERR: prefix =3D "ERROR"; break; case LOG_WARNING: prefix =3D "WARNING"; break; case LOG_NOTICE: prefix =3D "NOTICE"; break; case LOG_INFO: prefix =3D "INFO"; break; case LOG_DEBUG: prefix =3D "DEBUG"; break; default: prefix =3D "NOTICE"; break; } openlog (getprogname(), LOG_PID | LOG_PERROR, LOG_DAEMON); new_format =3D c_str_join (prefix, ": ", format, NULL); /* * 2022.12.18 * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D268436 * The freebsd libc syslog, vsyslog does not preserve the errno at the ti= me of * the call, so errno may change after the syslog call. */ //int saved_errno =3D errno; va_start (args, format); vsyslog (priority, new_format, args); va_end (args); //errno =3D saved_errno; free (new_format); closelog (); } #define c_log_critical(format, ...) \ c_log (LOG_CRIT, __FILE__ ":%d:%s: " format, \ __LINE__, __PRETTY_FUNCTION__, ## __VA_ARGS__) #define c_log_warning(format, ...) \ c_log (LOG_WARNING, __FILE__ ":%d:%s: " format, \ __LINE__, __PRETTY_FUNCTION__, ## __VA_ARGS__) #define c_log_info(format, ...) \ c_log (LOG_INFO, format, ## __VA_ARGS__) int main () { printf ("before: %d\n", errno); c_log_info ("Example: %d", errno); c_log_warning ("Example: %d", errno); c_log_critical ("Example: %d", errno); printf ("after: %d\n", errno); return 0; } When I tested this code in the past, there was an issue where errno was cha= nged after calling vsyslog(). So I used this: int saved_errno =3D errno; va_start (args, format); vsyslog (priority, new_format, args); va_end (args); errno =3D saved_errno; But now that I've tested it again, errno doesn't change after calling vsyslog(). //int saved_errno =3D errno; va_start (args, format); vsyslog (priority, new_format, args); va_end (args); //errno =3D saved_errno; So this issue seems to be resolved and I think we can close this issue. --=20 You are receiving this mail because: You are the assignee for the bug.=