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