Re: [systemd-devel] Unit configuration for FUSE file system

2012-05-03 Thread Stef Bon
2012/5/3 Nikolaus Rath :
> Stef Bon  writes:
>> That's why I advise to use a pidfile systemd can watch.
>
> I believe one of systemd's design goals is to actually get rid of pid
> files and related hacks. If I want to use systemd with a pidfile, I may
> just as well use systemd's sysvinit compatibility layer and stick with
> my traditional shell init script.

Well yes I understand.

Point is with your situation is that after it's umounted, the process
isn't terminated. It's doing "important things" (your own words).

Well that doesn't make the "mount" unit usefull.

I'm not aware on the capabilities of systemd too well, maybe one of
the entries like "ExecStop" in the service unit (see systemd.service)
maybe usefull. And maybe you have to set Requires=network.target in
the [Unit] part.

Stef
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] D-Bus services: automatically set Type=dbus?

2012-05-03 Thread Lennart Poettering
On Tue, 01.05.12 12:09, Bill Nottingham (nott...@redhat.com) wrote:

> The wpa_supplicant service we had in Fedora shipped this dbus service file:
> 
> ...
> [D-BUS Service]
> Name=fi.w1.wpa_supplicant1
> SystemdService=wpa_supplicant.service
> ...
> and the following wpa_supplicant.service file:
> 
> ...
> [Service]
> Type=forking
> ...
> 
> Should this be an error that systemd checks, or warns about - should any
> service referred to by a DBus service file automatically inherit Type=dbus,
> and the appropriate BusName argument?

Good point!

i have now changed git to:

a) generate an error when Type=dbus is set, but BusName= isn't
b) generate a warning if BusName= is set, but Type=dbus isn't
c) imply Type=dbus if BusName= is set, but Type= isn't explicitly

This should help detecting mistakes like this, and also allows us to
shorten the usual dbus unit files.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] SegFaults?!

2012-05-03 Thread Sven Anders
Hello!

I'm getting some SegFaults, which I can not explain. I think the problem
lies somewhere in my configuration or systemd makes some assumptions and
my system does not fulfill these requirements.

Nevertheless, I think the tools should not SegFault but issue an error
instead. By now I have no real idea where the problem lies.

If I run the tool in valgrind, they work.

Do you have any idea?


Regards
 Sven


root@system:/var/tmp/systemd-44 # gdb systemd-cgls
GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /usr/bin/systemd-cgls...Reading symbols from 
/usr/lib/debug/usr/bin/systemd-cgls.dbgsym...done.
done.
(gdb) run
Starting program: /usr/bin/systemd-cgls
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x00a2 in ?? ()
(gdb) up
#1  0x40127282 in pipe () at ../sysdeps/unix/syscall-template.S:82
82  ../sysdeps/unix/syscall-template.S: No such file or directory.
in ../sysdeps/unix/syscall-template.S
(gdb) up
#2  0x80004210 in pager_open () at src/pager.c:66
66  if (pipe(fd) < 0) {
(gdb) print fd
$1 = {1, -1073743132}
(gdb) up
#3  0x80002dee in main (argc=1, argv=0xbae4) at src/cgls.c:108
108 pager_open();




root@system# gdb systemd-loginctl
GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /bin/systemd-loginctl...Reading symbols from 
/usr/lib/debug/bin/systemd-loginctl.dbgsym...done.
done.
(gdb) run
Starting program: /bin/systemd-loginctl
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x00a2 in ?? ()
(gdb) bt
#0  0x00a2 in ?? ()
#1  0x40194282 in pipe () at ../sysdeps/unix/syscall-template.S:82
#2  0x8000cea0 in pager_open () at src/pager.c:66
#3  0x8000a22e in pager_open_if_enabled (bus=0x80018710, args=0xbae8, n=0) 
at src/login/loginctl.c:72
#4  list_sessions (bus=0x80018710, args=0xbae8, n=0) at 
src/login/loginctl.c:86
#5  0x8000ab16 in loginctl_main (argc=1, argv=0xbae4) at 
src/login/loginctl.c:1878
#6  main (argc=1, argv=0xbae4) at src/login/loginctl.c:1908
(gdb) up
#1  0x40194282 in pipe () at ../sysdeps/unix/syscall-template.S:82
82  ../sysdeps/unix/syscall-template.S: No such file or directory.
in ../sysdeps/unix/syscall-template.S
(gdb) up
#2  0x8000cea0 in pager_open () at src/pager.c:66
66  if (pipe(fd) < 0) {
(gdb) print fd
$1 = {22, 0}
(gdb) up
#3  0x8000a22e in pager_open_if_enabled (bus=0x80018710, args=0xbae8, n=0) 
at src/login/loginctl.c:72
72  pager_open();




root@system # gdb systemd-loginctl
GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /bin/systemd-loginctl...Reading symbols from 
/usr/lib/debug/bin/systemd-loginctl.dbgsym...done.
done.
(gdb) run
Starting program: /bin/systemd-loginctl
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x00a2 in ?? ()
(gdb) bt
#0  0x00a2 in ?? ()
#1  0x40194282 in pipe () at ../sysdeps/unix/syscall-template.S:82
#2  0x8000cea0 in pager_open () at src/pager.c:66
#3  0x8000a22e in pager_open_if_enabled (bus=0x80018710, args=0xbae8, n=0) 
at src/login/loginctl.c:72
#4  list_sessions (bus=0x80018710, args=0xbae8, n=0) at 
src/login/loginctl.c:86
#5  0x8000ab16 in loginctl_main (argc=1, argv=0xbae4) at 
src/login/loginctl.c:1878
#6  main (argc=1, argv=0xbae4) at src/login/loginctl.c:1908
(gdb) up
#1  0x40194282 in pipe () at ../sysdeps/unix/syscall-template.S:82
82  ../sysdeps/unix/syscall-template.S: No such file or directory.
in ../sysdeps/unix/syscall-template.S
(gdb) up
#2  0x8000cea0 in pager_open () at src/pager.c:66
66  if (pipe(fd) < 0) {
(gdb) print fd
$1 =

Re: [systemd-devel] SegFaults?!

2012-05-03 Thread Lennart Poettering
On Thu, 03.05.12 18:14, Sven Anders (and...@anduras.de) wrote:

> Hello!
> 
> I'm getting some SegFaults, which I can not explain. I think the problem
> lies somewhere in my configuration or systemd makes some assumptions and
> my system does not fulfill these requirements.
> 
> Nevertheless, I think the tools should not SegFault but issue an error
> instead. By now I have no real idea where the problem lies.
> 
> If I run the tool in valgrind, they work.
> 
> Do you have any idea?

Hmm, I don't see how a system call would result in a SIGSEGV. This is
really weird...

The fd[] array passed to pipe() is allocated on the stack. This suggests
that your stack is getting corrupted somehow.

Do things work correctly if you run stuff with --no-pager?

Lennart

-- 
Lennart Poettering - Red Hat, Inc.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [CFP] Linux Plumbers Conf Track "Boot & Base OS"

2012-05-03 Thread Lennart Poettering
Heya,

Kay and I are running the "Boot & Base OS" miniconf at the Linux
Plumbers Conference (San Diego) this year. We are looking for talks for
it!

http://wiki.linuxplumbersconf.org/2012:boot_and_base_os

Are you working on boot/base OS stuff, and have something exciting to
talk about? Then please submit a proposal!

The submission scheme is rather stupid these days involving
launchpad. Thankfully there's an alternative way to submit talks:

http://www.linuxplumbersconf.org/2012/2012-lpc-call-for-proposals-take-2/

Please follow these instructions, but also please CC us!

If you are wondering if your topic might fit in, please have a look at
the first URL I posted which includes a terse description of the
intended topic of this miniconf. If in doubt, submit -- the worst that
will happen is that we respectfully decline if its too far away from our
topic ;-).

Anyway, all submissions appreciated!

Thanks,

Lennart

-- 
Lennart Poettering - Red Hat, Inc.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] SegFaults?!

2012-05-03 Thread Sven Anders
Am 03.05.2012 18:33, schrieb Lennart Poettering:
> On Thu, 03.05.12 18:14, Sven Anders (and...@anduras.de) wrote:
> 
>> Hello!
>>
>> I'm getting some SegFaults, which I can not explain. I think the problem
>> lies somewhere in my configuration or systemd makes some assumptions and
>> my system does not fulfill these requirements.
>>
>> Nevertheless, I think the tools should not SegFault but issue an error
>> instead. By now I have no real idea where the problem lies.
>>
>> If I run the tool in valgrind, they work.
>>
>> Do you have any idea?
> 
> Hmm, I don't see how a system call would result in a SIGSEGV. This is
> really weird...
> 
> The fd[] array passed to pipe() is allocated on the stack. This suggests
> that your stack is getting corrupted somehow.
> 
> Do things work correctly if you run stuff with --no-pager?

Curiously not. Only if I run this in valgrind...

I had another strange SegFault when using systemd-journalctl, but this
is now gone... So I suspected a misconfiguration first...

This is the same compilation and other tools and systemd itself are
running fine. I'm trying this in KVM with Linux kernel 3.2.2.


(gdb) run
Starting program: /usr/bin/systemd-cgls --no-pager
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x00a2 in ?? ()
(gdb) bt
#0  0x00a2 in ?? ()
#1  0x40126a86 in access () at ../sysdeps/unix/syscall-template.S:82
#2  0x80004107 in cg_fix_path (path=0x8000c040 "/sys/fs/cgroup/systemd", 
result=0xb960) at src/cgroup-util.c:1065
#3  0x800034cf in show_cgroup_by_path (path=0x8000c040 
"/sys/fs/cgroup/systemd", prefix=0x80008784 "", n_columns=162, 
kernel_threads=false)
at src/cgroup-show.c:176
#4  0x800037b6 in show_cgroup (controller=0x80007f5e "name=systemd", 
path=0x80008712 "/", prefix=0x0, n_columns=0, kernel_threads=false) at
src/cgroup-show.c:257
#5  0x80002fbc in main (argc=2, argv=0xbae4) at src/cgls.c:148
(gdb) up
#1  0x40126a86 in access () at ../sysdeps/unix/syscall-template.S:82
82  ../sysdeps/unix/syscall-template.S: No such file or directory.
in ../sysdeps/unix/syscall-template.S
(gdb) up
#2  0x80004107 in cg_fix_path (path=0x8000c040 "/sys/fs/cgroup/systemd", 
result=0xb960) at src/cgroup-util.c:1065
1065access(path, F_OK) >= 0) {


These are the last lines of a strace:

[...]
830   stat64(".", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
830   stat64("/var/tmp/systemd-44", {st_mode=S_IFDIR|0775, st_size=4096, ...}) 
= 0
830   open("/proc/1/cgroup", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
830   fstat64(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
830   mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) 
= 0x4002d000
830   read(3, "5:freezer:/\n4:devices:/\n3:cpuacc"..., 1024) = 74
830   close(3)  = 0
830   munmap(0x4002d000, 4096)  = 0
830   lstat64("/sys/fs/cgroup", {st_mode=S_IFDIR|0755, st_size=180, ...}) = 0
830   lstat64("/sys/fs", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
830   ioctl(1, TIOCGWINSZ, {ws_row=35, ws_col=162, ws_xpixel=0, ws_ypixel=0}) = 0
830   --- SIGSEGV (Segmentation fault) @ 0 (0) ---
830   +++ killed by SIGSEGV (core dumped) +++


Really strange!

Regards
 Sven Anders

-- 
 Sven Anders  () UTF-8 Ribbon Campaign
 /\ Support plain text e-mail
 ANDURAS intranet security AG
 Messestrasse 3 - 94036 Passau - Germany
 Web: www.anduras.de - Tel: +49 (0)851-4 90 50-0 - Fax: +49 (0)851-4 90 50-55

Those who would give up essential Liberty, to purchase a little
temporary Safety, deserve neither Liberty nor Safety.
  - Benjamin Franklin
<>___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] systemd-analyze: add a --user option to support user instances

2012-05-03 Thread Patrick McCarty
---
 src/analyze/systemd-analyze |   22 ++
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/analyze/systemd-analyze b/src/analyze/systemd-analyze
index a49fbb7..ad7bd9a 100755
--- a/src/analyze/systemd-analyze
+++ b/src/analyze/systemd-analyze
@@ -69,9 +69,9 @@ def draw_text(context, x, y, text, size = 12, r = 0, g = 0, b 
= 0, vcenter = 0.5
 context.restore()
 
 def help():
-sys.stdout.write("""systemd-analyze time
-systemd-analyze blame
-systemd-analyze plot
+sys.stdout.write("""systemd-analyze [--user] time
+systemd-analyze [--user] blame
+systemd-analyze [--user] plot
 
 Process systemd profiling information
 
@@ -80,8 +80,14 @@ Process systemd profiling information
 
 
 bus = dbus.SystemBus()
+command_index = 1
 
-if len(sys.argv) <= 1 or sys.argv[1] == 'time':
+if len(sys.argv) > 1 and sys.argv[1] == '--user':
+bus = dbus.SessionBus()
+command_index = 2
+
+
+if len(sys.argv) <= command_index or sys.argv[command_index] == 'time':
 
 initrd_time, start_time, finish_time = acquire_start_time()
 
@@ -98,7 +104,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == 'time':
 finish_time/1000)
 
 
-elif sys.argv[1] == 'blame':
+elif sys.argv[command_index] == 'blame':
 
 data = acquire_time_data()
 s = sorted(data, key = lambda i: i[2] - i[1], reverse = True)
@@ -113,7 +119,7 @@ elif sys.argv[1] == 'blame':
 
 sys.stdout.write("%6lums %s\n" % ((aet - ixt) / 1000, name))
 
-elif sys.argv[1] == 'plot':
+elif sys.argv[command_index] == 'plot':
 import cairo, os
 
 initrd_time, start_time, finish_time = acquire_start_time()
@@ -269,8 +275,8 @@ elif sys.argv[1] == 'plot':
 finish_time/1000), hcenter = 0, vcenter = -1)
 
 surface.finish()
-elif sys.argv[1] in ("help", "--help", "-h"):
+elif sys.argv[command_index] in ("help", "--help", "-h"):
 help()
 else:
-sys.stderr.write("Unknown verb '%s'.\n" % sys.argv[1])
+sys.stderr.write("Unknown verb '%s'.\n" % sys.argv[command_index])
 sys.exit(1)
-- 
1.7.10

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] systemd-analyze: add a --user option to support user instances

2012-05-03 Thread Kok, Auke-jan H
Thanks Patrick, this is exactly what I needed.

Lennert, Kay - this will make pretty graphs of the user session startup.

I've posted an example of the output here:
http://foo-projects.org/~sofar/systemd-user-2.svg

Auke

>
> On Thu, May 3, 2012 at 1:42 PM, Patrick McCarty <
> patrick.mcca...@linux.intel.com> wrote:
>
>> ---
>>  src/analyze/systemd-analyze |   22 ++
>>  1 file changed, 14 insertions(+), 8 deletions(-)
>>
>> diff --git a/src/analyze/systemd-analyze b/src/analyze/systemd-analyze
>> index a49fbb7..ad7bd9a 100755
>> --- a/src/analyze/systemd-analyze
>> +++ b/src/analyze/systemd-analyze
>> @@ -69,9 +69,9 @@ def draw_text(context, x, y, text, size = 12, r = 0, g
>> = 0, b = 0, vcenter = 0.5
>> context.restore()
>>
>>  def help():
>> -sys.stdout.write("""systemd-analyze time
>> -systemd-analyze blame
>> -systemd-analyze plot
>> +sys.stdout.write("""systemd-analyze [--user] time
>> +systemd-analyze [--user] blame
>> +systemd-analyze [--user] plot
>>
>>  Process systemd profiling information
>>
>> @@ -80,8 +80,14 @@ Process systemd profiling information
>>
>>
>>  bus = dbus.SystemBus()
>> +command_index = 1
>>
>> -if len(sys.argv) <= 1 or sys.argv[1] == 'time':
>> +if len(sys.argv) > 1 and sys.argv[1] == '--user':
>> +bus = dbus.SessionBus()
>> +command_index = 2
>> +
>> +
>> +if len(sys.argv) <= command_index or sys.argv[command_index] == 'time':
>>
>> initrd_time, start_time, finish_time = acquire_start_time()
>>
>> @@ -98,7 +104,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == 'time':
>> finish_time/1000)
>>
>>
>> -elif sys.argv[1] == 'blame':
>> +elif sys.argv[command_index] == 'blame':
>>
>> data = acquire_time_data()
>> s = sorted(data, key = lambda i: i[2] - i[1], reverse = True)
>> @@ -113,7 +119,7 @@ elif sys.argv[1] == 'blame':
>>
>> sys.stdout.write("%6lums %s\n" % ((aet - ixt) / 1000,
>> name))
>>
>> -elif sys.argv[1] == 'plot':
>> +elif sys.argv[command_index] == 'plot':
>> import cairo, os
>>
>> initrd_time, start_time, finish_time = acquire_start_time()
>> @@ -269,8 +275,8 @@ elif sys.argv[1] == 'plot':
>> finish_time/1000), hcenter = 0, vcenter = -1)
>>
>> surface.finish()
>> -elif sys.argv[1] in ("help", "--help", "-h"):
>> +elif sys.argv[command_index] in ("help", "--help", "-h"):
>> help()
>>  else:
>> -sys.stderr.write("Unknown verb '%s'.\n" % sys.argv[1])
>> +sys.stderr.write("Unknown verb '%s'.\n" %
>> sys.argv[command_index])
>> sys.exit(1)
>> --
>> 1.7.10
>>
>> ___
>> systemd-devel mailing list
>> systemd-devel@lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
>>
>
>
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] man: clarify _TRANSPORT

2012-05-03 Thread Shawn Landden
"resp." where it was confuses reader that stdout and stderr might go to 
differn't places

Signed-off-by: Shawn Landden 
---
 man/systemd.journal-fields.xml |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man/systemd.journal-fields.xml b/man/systemd.journal-fields.xml
index 99b1caa..c523ab0 100644
--- a/man/systemd.journal-fields.xml
+++ b/man/systemd.journal-fields.xml
@@ -281,8 +281,8 @@
 journal protocol, for the
 those read from a services'
 standard output or error
-output, resp. for those read
-from the kernel.
+output, and for those read
+from the kernel, resp.
 
 
 
-- 
1.7.9.5

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] man: clarify _TRANSPORT

2012-05-03 Thread Lennart Poettering
On Thu, 03.05.12 15:19, Shawn Landden (shawnland...@gmail.com) wrote:

> "resp." where it was confuses reader that stdout and stderr might go to 
> differn't places

Thanks, applied!

Lennart

-- 
Lennart Poettering - Red Hat, Inc.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] systemd-analyze: add a --user option to support user instances

2012-05-03 Thread Lennart Poettering
On Thu, 03.05.12 13:42, Patrick McCarty (patrick.mcca...@linux.intel.com) wrote:

Heya,

thanks fo the patch! If have commited this now, but I believe this could
use some love still. For example, it makes little sense to show the grey
kenrel/initrd/userspace bars for the user session. Also, we probably
should start using proper getopt here instead of parsing the cmdline
manually...

Lennart

>  src/analyze/systemd-analyze |   22 ++
>  1 file changed, 14 insertions(+), 8 deletions(-)
> 
> diff --git a/src/analyze/systemd-analyze b/src/analyze/systemd-analyze


Lennart

-- 
Lennart Poettering - Red Hat, Inc.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] systemd-analyze: switch to python getopt for argument parsing

2012-05-03 Thread Shawn Landden
this uses gnu style getopt, so you can put the opts at the end: (e.g.)
systemd-analyze blame --user
---
 src/analyze/systemd-analyze |   38 --
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/analyze/systemd-analyze b/src/analyze/systemd-analyze
index ad7bd9a..ec68da1 100755
--- a/src/analyze/systemd-analyze
+++ b/src/analyze/systemd-analyze
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-import dbus, sys
+import getopt, dbus, sys
 
 def acquire_time_data():
 
@@ -68,7 +68,7 @@ def draw_text(context, x, y, text, size = 12, r = 0, g = 0, b 
= 0, vcenter = 0.5
 
 context.restore()
 
-def help():
+def usage():
 sys.stdout.write("""systemd-analyze [--user] time
 systemd-analyze [--user] blame
 systemd-analyze [--user] plot
@@ -78,16 +78,24 @@ Process systemd profiling information
   -h --help Show this help
 """)
 
-
 bus = dbus.SystemBus()
-command_index = 1
-
-if len(sys.argv) > 1 and sys.argv[1] == '--user':
-bus = dbus.SessionBus()
-command_index = 2
 
+try:
+opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ["help", "user"])
+except getopt.GetoptError, err:
+print str(err)
+usage()
+sys.exit(2)
+for o, a in opts:
+if o in ("-h", "--help"):
+usage()
+sys.exit()
+if o == '--user':
+bus = dbus.SessionBus()
+else:
+assert False, "unhandled option"
 
-if len(sys.argv) <= command_index or sys.argv[command_index] == 'time':
+if len(args) <= 0 or args[0] == 'time':
 
 initrd_time, start_time, finish_time = acquire_start_time()
 
@@ -104,7 +112,7 @@ if len(sys.argv) <= command_index or 
sys.argv[command_index] == 'time':
 finish_time/1000)
 
 
-elif sys.argv[command_index] == 'blame':
+elif args[0] == 'blame':
 
 data = acquire_time_data()
 s = sorted(data, key = lambda i: i[2] - i[1], reverse = True)
@@ -119,7 +127,7 @@ elif sys.argv[command_index] == 'blame':
 
 sys.stdout.write("%6lums %s\n" % ((aet - ixt) / 1000, name))
 
-elif sys.argv[command_index] == 'plot':
+elif args[0] == 'plot':
 import cairo, os
 
 initrd_time, start_time, finish_time = acquire_start_time()
@@ -275,8 +283,10 @@ elif sys.argv[command_index] == 'plot':
 finish_time/1000), hcenter = 0, vcenter = -1)
 
 surface.finish()
-elif sys.argv[command_index] in ("help", "--help", "-h"):
-help()
+
+elif args[0] == 'help':
+usage()
+sys.exit()
 else:
-sys.stderr.write("Unknown verb '%s'.\n" % sys.argv[command_index])
+sys.stderr.write("Unknown verb '%s'.\n" % args[0])
 sys.exit(1)
-- 
1.7.9.5

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] systemd-analyze: switch to python getopt for argument parsing

2012-05-03 Thread Shawn Landden
this uses gnu style getopt, so you can put the opts at the end: (e.g.)
systemd-analyze blame --user

v2
---
 src/analyze/systemd-analyze |   56 ++-
 1 file changed, 39 insertions(+), 17 deletions(-)

diff --git a/src/analyze/systemd-analyze b/src/analyze/systemd-analyze
index ad7bd9a..48d30ce 100755
--- a/src/analyze/systemd-analyze
+++ b/src/analyze/systemd-analyze
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-import dbus, sys
+import getopt, dbus, sys
 
 def acquire_time_data():
 
@@ -68,7 +68,7 @@ def draw_text(context, x, y, text, size = 12, r = 0, g = 0, b 
= 0, vcenter = 0.5
 
 context.restore()
 
-def help():
+def usage():
 sys.stdout.write("""systemd-analyze [--user] time
 systemd-analyze [--user] blame
 systemd-analyze [--user] plot
@@ -78,16 +78,11 @@ Process systemd profiling information
   -h --help Show this help
 """)
 
+def help():
+usage()
+sys.exit()
 
-bus = dbus.SystemBus()
-command_index = 1
-
-if len(sys.argv) > 1 and sys.argv[1] == '--user':
-bus = dbus.SessionBus()
-command_index = 2
-
-
-if len(sys.argv) <= command_index or sys.argv[command_index] == 'time':
+def time():
 
 initrd_time, start_time, finish_time = acquire_start_time()
 
@@ -104,7 +99,7 @@ if len(sys.argv) <= command_index or sys.argv[command_index] 
== 'time':
 finish_time/1000)
 
 
-elif sys.argv[command_index] == 'blame':
+def blame():
 
 data = acquire_time_data()
 s = sorted(data, key = lambda i: i[2] - i[1], reverse = True)
@@ -119,7 +114,7 @@ elif sys.argv[command_index] == 'blame':
 
 sys.stdout.write("%6lums %s\n" % ((aet - ixt) / 1000, name))
 
-elif sys.argv[command_index] == 'plot':
+def plot():
 import cairo, os
 
 initrd_time, start_time, finish_time = acquire_start_time()
@@ -275,8 +270,35 @@ elif sys.argv[command_index] == 'plot':
 finish_time/1000), hcenter = 0, vcenter = -1)
 
 surface.finish()
-elif sys.argv[command_index] in ("help", "--help", "-h"):
-help()
-else:
-sys.stderr.write("Unknown verb '%s'.\n" % sys.argv[command_index])
+
+def unknown_verb():
+sys.stderr.write("Unknown verb '%s'.\n" % args[0])
+usage()
 sys.exit(1)
+
+bus = dbus.SystemBus()
+
+try:
+opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ["help", "user"])
+except getopt.GetoptError, err:
+print str(err)
+usage()
+sys.exit(2)
+for o, a in opts:
+if o in ("-h", "--help"):
+help()
+elif o == '--user':
+bus = dbus.SessionBus()
+else:
+assert False, "unhandled option"
+
+verb = {'time' : time,
+   'blame': blame,
+   'plot' : plot,
+   'help' : help,
+   }
+
+if len(args) == 0:
+time()
+else:
+verb.get(args[0], unknown_verb)()
-- 
1.7.9.5

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel