From patchwork Tue Nov 17 11:17:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Milz X-Patchwork-Id: 69014 Received: from [127.0.0.1] by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1kezCX-00FzFa-Bc; Tue, 17 Nov 2020 11:31:09 +0000 Received: from colin.muc.de ([193.149.48.1] helo=mail.muc.de) by www.linuxtv.org with smtp (Exim 4.92) (envelope-from ) id 1kezCV-00FzFU-KG for vdr@linuxtv.org; Tue, 17 Nov 2020 11:31:08 +0000 Received: (qmail 63219 invoked by uid 66); 17 Nov 2020 11:31:06 -0000 Received: from nathan (ipbcc1192f.dynamic.kabel-deutschland.de [188.193.25.47]) by seneca.muc.de (Postfix) with ESMTPSA id B65A81E1 for ; Tue, 17 Nov 2020 12:17:32 +0100 (CET) Date: Tue, 17 Nov 2020 12:17:31 +0100 From: Harald Milz To: vdr@linuxtv.org Message-ID: <20201117111731.GA260921@nathan> MIME-Version: 1.0 Content-Disposition: inline X-LSpam-Score: -1.9 (-) X-LSpam-Report: No, score=-1.9 required=5.0 tests=BAYES_00=-1.9 autolearn=ham autolearn_force=no Subject: [vdr] option parsing for --log still broken X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: VDR Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: VDR Mailing List Errors-To: vdr-bounces@linuxtv.org Sender: "vdr" Hi Klaus and all, it appears that option parsing for the --log option is still broken, as described in this thread: https://www.vdr-portal.de/forum/index.php?thread/108924-gel%C3%B6st-logging-von-yavdr-in-separaten-logfiles-anstelle-des-syslog-und-probleme/ Short version: vdr stops parsing the remainder of the command line at the point of --log=2.6. Long version: The problem is in the getopt code in vdr.c: case 'l': { char *p = strchr(optarg, '.'); if (p) *p = 0; if (isnumber(optarg)) { int l = atoi(optarg); if (0 <= l && l <= 3) { SysLogLevel = l; if (!p) break; if (isnumber(p + 1)) { int l = atoi(p + 1); if (0 <= l && l <= 7) { int targets[] = { LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7 }; SysLogTarget = targets[l]; break; } } } } if (p) *p = '.'; fprintf(stderr, "vdr: invalid log level: %s\n", optarg); return 2; } Initially, the point is replaced by a NULL byte in order to be able to atoi() both numbers (if (p) *p = 0;). This replacing takes place _in place_. In theory, the replace should be reverted at the end of the code snippet (if (p) *p = '.';) BUT if one of the branches involving a break is executed, the revert is never invoked, and the original command line remains broken so that the remaining command line options are not getting evaluated. Consequently, what used to be vdr -w 60 -g -u vdr -l 2.6 -P plugin1 -P plugin2 becomes vdr -w 60 -g -u vdr -l 2 6 -P plugin1 -P plugin2 and the modules will not get loaded. The thread mentioned above speaks of upstart & co but I have the same issue in a docker container with explicit program start in a shell script whithout any upstart or anything. I now helped myself putting the -l at the end of the command line but I still cannot send the vdr log to a different facility because the dangling 6 is not getting evaluated. My suggestion would be to not evaluate the optarg string directly but create a copy of optarg first, and work with the copy. This way, the original command line is unchanged. Sample patch attached, untested but it should do the trick. diff -ur vdr-2.4.4-ORIG/vdr.c vdr-2.4.4/vdr.c --- vdr-2.4.4-ORIG/vdr.c 2020-05-18 18:47:29.000000000 +0200 +++ vdr-2.4.4/vdr.c 2020-11-17 12:15:16.605470457 +0100 @@ -413,11 +413,14 @@ fprintf(stderr, "vdr: invalid instance id: %s\n", optarg); return 2; case 'l': { - char *p = strchr(optarg, '.'); + int len = strlen(optarg); + char copy[4]; + strncpy (optarg, copy, len); + char *p = strchr(copy, '.'); if (p) *p = 0; - if (isnumber(optarg)) { - int l = atoi(optarg); + if (isnumber(copy)) { + int l = atoi(copy); if (0 <= l && l <= 3) { SysLogLevel = l; if (!p) @@ -432,8 +435,6 @@ } } } - if (p) - *p = '.'; fprintf(stderr, "vdr: invalid log level: %s\n", optarg); return 2; }