Skip to contentSkip to conversation

RFC: Allow 'ip' to run in daemon mode?

DISCUSSION Ben Greear 3 participants 4 messages Jun 29, 2010 – Jul 1, 2010

Subsystems (2)
lore
Share & tools
lore

Ben Greear

author
#0 lore raw

I'm considering modifying 'ip' to be able to run in daemon mode so that I can do lots of IP commands without having to pay the startup cost of iproute.

The -batch option almost works, but it's hard to programatically figure out failure codes.

I'm thinking about making these changes:

1) Move all of the error printing code into common methods (basically, wrap printf). In daemon mode this text can be sent back to the calling process, and in normal mode, it will be printed to stdout/stderr as it is currently.

2) Remove all or most calls to 'exit' and instead return error codes to the calling logic.

3) Add ability to listen on a unix socket for commands, basically treat them just like batch commands, one command per packet.

4) Return well formatted error code and text response to calling process over the unix socket, maybe something like:

RV: [errno or equiv, zero for success]\n
CMD: [ command string this relates to ]\n
[ Optional free form text ]

Does something like this have any chance of upstream inclusion?

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#1 lore raw
Quoted 23 lines · Ben Greear

I'm considering modifying 'ip' to be able to run in daemon mode so that I can do lots of IP commands without having to pay the startup cost of iproute.

The -batch option almost works, but it's hard to programatically figure out failure codes.

I'm thinking about making these changes:

1) Move all of the error printing code into common methods (basically, wrap printf). In daemon mode this text can be sent back to the calling process, and in normal mode, it will be printed to stdout/stderr as it is currently.

2) Remove all or most calls to 'exit' and instead return error codes to the calling logic.

3) Add ability to listen on a unix socket for commands, basically treat them just like batch commands, one command per packet.

4) Return well formatted error code and text response to calling process over the unix socket, maybe something like:

Quoted 6 lines

RV: [errno or equiv, zero for success]\n
CMD: [ command string this relates to ]\n
[ Optional free form text ]

Does something like this have any chance of upstream inclusion?

Hi Ben,

can't you achieve as much by omitting 3) and using stdio (cleanly)? Or in other words, fix batch mode rather than adding another mode. Or are you worried about backwards-compatibility?

author
#2 lore raw
Quoted 29 lines · Simon Horman
Quoted 28 lines · Ben Greear

I'm considering modifying 'ip' to be able to run in daemon mode so that I can do lots of IP commands without having to pay the startup cost of iproute.

The -batch option almost works, but it's hard to programatically figure out failure codes.

I'm thinking about making these changes:

1) Move all of the error printing code into common methods (basically, wrap printf). In daemon mode this text can be sent back to the calling process, and in normal mode, it will be printed to stdout/stderr as it is currently.

2) Remove all or most calls to 'exit' and instead return error codes to the calling logic.

3) Add ability to listen on a unix socket for commands, basically treat them just like batch commands, one command per packet.

4) Return well formatted error code and text response to calling process over the unix socket, maybe something like:

RV: [errno or equiv, zero for success]\n
CMD: [ command string this relates to ]\n
[ Optional free form text ]

Quoted 7 lines
Quoted 1 line

Does something like this have any chance of upstream inclusion?

Hi Ben,

can't you achieve as much by omitting 3) and using stdio (cleanly)? Or in other words, fix batch mode rather than adding another mode. Or are you worried about backwards-compatibility?

I think the most of the work will be in steps 1 and 2. Adding a listening socket and dealing with that is probably 50-100 lines of code.

I'd be happy to attempt steps 1, 2, and possibly 4 for standard iproute2. If the unix socket thing still isn't wanted, it would be relatively easy for me to carry a patch to enable it in my own code.

I think a lot of folks are scraping the output of 'ip', so backwards compat of the error messages is a concern.

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#3 lore raw
Quoted 41 lines · On Thu, 01 Jul 2010 08:41:45 -0700 Ben Greear <[email protected]> wrote:
Quoted 29 lines · Simon Horman
Quoted 28 lines · Ben Greear

I'm considering modifying 'ip' to be able to run in daemon mode so that I can do lots of IP commands without having to pay the startup cost of iproute.

The -batch option almost works, but it's hard to programatically figure out failure codes.

I'm thinking about making these changes:

1) Move all of the error printing code into common methods (basically, wrap printf). In daemon mode this text can be sent back to the calling process, and in normal mode, it will be printed to stdout/stderr as it is currently.

2) Remove all or most calls to 'exit' and instead return error codes to the calling logic.

3) Add ability to listen on a unix socket for commands, basically treat them just like batch commands, one command per packet.

4) Return well formatted error code and text response to calling process over the unix socket, maybe something like:

RV: [errno or equiv, zero for success]\n
CMD: [ command string this relates to ]\n
[ Optional free form text ]

Quoted 7 lines
Quoted 1 line

Does something like this have any chance of upstream inclusion?

Hi Ben,

can't you achieve as much by omitting 3) and using stdio (cleanly)? Or in other words, fix batch mode rather than adding another mode. Or are you worried about backwards-compatibility?

I think the most of the work will be in steps 1 and 2. Adding a listening socket and dealing with that is probably 50-100 lines of code.

Quoted 6 lines

I'd be happy to attempt steps 1, 2, and possibly 4 for standard iproute2. If the unix socket thing still isn't wanted, it would be relatively easy for me to carry a patch to enable it in my own code.

I think a lot of folks are scraping the output of 'ip', so backwards compat of the error messages is a concern.

Use libnl and write a real service. Maybe even use json