803fb7
From 2eb2ddac8eaa258dd1ac0b2d4c1aefef9b66a989 Mon Sep 17 00:00:00 2001
803fb7
From: Susant Sahani <ssahani@users.noreply.github.com>
803fb7
Date: Mon, 30 May 2016 20:23:15 +0530
803fb7
Subject: [PATCH] systemctl: return diffrent error code if service exist or not
803fb7
 (#3385)
803fb7
MIME-Version: 1.0
803fb7
Content-Type: text/plain; charset=UTF-8
803fb7
Content-Transfer-Encoding: 8bit
803fb7
803fb7
Before:
803fb7
[sus@maximus bz-1256858]$ systemctl status rsyslog.service;echo $?
803fb7
● rsyslog.service - System Logging Service
803fb7
   Loaded: loaded (/usr/lib/systemd/system/rsyslog.service; enabled; vendor
803fb7
preset: enabled)
803fb7
  Drop-In: /etc/systemd/system/rsyslog.service.d
803fb7
           └─50-CPUShares.conf
803fb7
   Active: inactive (dead) since Mon 2016-05-30 11:54:25 IST; 2h 26min ago
803fb7
     Docs: man:rsyslogd(8)
803fb7
           http://www.rsyslog.com/doc/
803fb7
  Process: 1159 ExecStart=/usr/sbin/rsyslogd -n $SYSLOGD_OPTIONS (code=exited,
803fb7
status=0/SUCCESS)
803fb7
 Main PID: 1159 (code=exited, status=0/SUCCESS)
803fb7
803fb7
May 30 11:07:50 maximus systemd[1]: Starting System Logging Service...
803fb7
May 30 11:07:50 maximus systemd[1]: Started System Logging Service.
803fb7
May 30 11:54:25 maximus systemd[1]: Stopping System Logging Service...
803fb7
May 30 11:54:25 maximus systemd[1]: Stopped System Logging Service.
803fb7
3
803fb7
[sus@maximus bz-1256858]$ systemctl status hello.service;echo $?
803fb7
● hello.service
803fb7
   Loaded: not-found (Reason: No such file or directory)
803fb7
   Active: inactive (dead)
803fb7
3
803fb7
803fb7
After:
803fb7
$ ./systemctl status hello.service;echo $?
803fb7
Failed to dump process list, ignoring: Access denied
803fb7
● hello.service
803fb7
   Loaded: not-found (Reason: No such file or directory)
803fb7
   Active: inactive (dead)
803fb7
4
803fb7
[sus@maximus bz-1256858]$  ./systemctl status rsyslog.service;echo $?
803fb7
Failed to dump process list, ignoring: Access denied
803fb7
● rsyslog.service - System Logging Service
803fb7
   Loaded: loaded (/usr/lib/systemd/system/rsyslog.service; enabled; vendor
803fb7
preset: enabled)
803fb7
  Drop-In: /etc/systemd/system/rsyslog.service.d
803fb7
           └─50-CPUShares.conf
803fb7
   Active: inactive (dead) since Mon 2016-05-30 11:54:25 IST; 2h 24min ago
803fb7
     Docs: man:rsyslogd(8)
803fb7
           http://www.rsyslog.com/doc/
803fb7
  Process: 1159 ExecStart=/usr/sbin/rsyslogd -n $SYSLOGD_OPTIONS (code=exited,
803fb7
status=0/SUCCESS)
803fb7
 Main PID: 1159 (code=exited, status=0/SUCCESS)
803fb7
803fb7
May 30 11:07:50 maximus systemd[1]: Starting System Logging Service...
803fb7
May 30 11:07:50 maximus systemd[1]: Started System Logging Service.
803fb7
May 30 11:54:25 maximus systemd[1]: Stopping System Logging Service...
803fb7
May 30 11:54:25 maximus systemd[1]: Stopped System Logging Service.
803fb7
3
803fb7
803fb7
Fixes: 1092
803fb7
803fb7
(cherry picked from commit ca473d572f0d2d8f547ff787ae67afd489a3f15e)
803fb7
Resolves: #1047466
803fb7
---
803fb7
 src/systemctl/systemctl.c | 2 ++
803fb7
 1 file changed, 2 insertions(+)
803fb7
803fb7
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
803fb7
index 95ddf3be7..6079d60db 100644
803fb7
--- a/src/systemctl/systemctl.c
803fb7
+++ b/src/systemctl/systemctl.c
803fb7
@@ -4295,6 +4295,8 @@ static int show_one(
803fb7
                  */
803fb7
                 if (info.pid_file && access(info.pid_file, F_OK) == 0)
803fb7
                         r = 1;
803fb7
+                else if (streq_ptr(info.load_state, "not-found") && streq_ptr(info.active_state, "inactive"))
803fb7
+                        r = 4;
803fb7
                 else
803fb7
                         r = 3;
803fb7
         }