:: Re: [DNG] Systemd Shims
Página Principal
Delete this message
Reply to this message
Autor: Edward Bartolo
Data:  
Para: dng
Assunto: Re: [DNG] Systemd Shims
As it is, the frontend can connect on user request. The user can run
the frontend application, click connect and terminate the application
and the connection will continue to be functional. This is real KISS
in practice but I can also make the application automatically run on
startup of the OS.

Then the frontend can automatically attempt a connection prompting
the user if no connections are set up.

In the first case, I can hide the application window altogether only
showing it on failing to connect.

What do you suggest?

> -----------------------------------------------------------------------------
> On 19/08/2015, marc <marcxdv@???> wrote:
>> Hello
>>
>>> Now, I should think, the buffer overruns should not be possible, but I
>>> am open to criticism. Buffer overruns are not something to be proud of
>>> and correction when taken appropriately is a blessing.
>>>
>>> Now, I will sleep as I am totally exhausted from coding all day long.
>>
>> Well, you deserved a good rest - congratulations for making the
>> effort to learn something and contributing software. Doing something
>> almost always beats talking about it.
>>
>> Here is some feedback from me - for tomorrow, use or don't use.
>>
>>   * The main() function is special, returning negative values
>>     in it doesn't have the expected results - generally values
>>     between 0 and 255 are possible. Convention is 0 is success,
>>     1 some sort of alternative success and larger numbers a
>>     failure. /usr/include/sysexits.h defines some common failure
>>     modes, though not that many applications use those codes.

>>
>>     Anyway - try for yourself: run a program which returns a negative
>>     value and then use "echo $?" after it completes to see what
>>     actually made it back

>>
>> * In your deletion logic you use
>>
>>         int deleteConnect(char* essid) //argv[2]
>>         {
>>                 //char* s = 0;
>>                 char command[1024];
>>                 strcpy(command, "/bin/rm /etc/network/wifi/");
>>                 strcat(command, essid);
>>                 int q = exec(command, 0);
>>                 //printf(s);
>>                 return q;
>>         }

>>
>>     So it turns out there is a system call which is used internally
>>     by rm to do the deletion. It is called unlink (man 2 unlink)

>>
>>     Using it means you could do

>>
>>         int deleteConnect(char* essid) //argv[2]
>>         {
>>                 char command[SIZE];
>>                 int result;
>>                 result = snprintf(command, SIZE, "/etc/network/wifi/%s",
>> essid)
>>                 if(result >= SIZE){
>>                   return -1;
>>                 }
>>                 return unlink(command);
>>         }

>>
>>    Code size-wise it doesn't look that different, but instead of
>>    creating a shell process which then launches a rm process which
>>    then does the unlink, you can do the unlink yourself - which
>>    is faster and has fewer external interactions. It also means
>>    that by looking at the errno variable if unlink fails you can
>>    generate your own error messages.

>>
>>    Using "strace -f " on the program when calling the two versions
>>    of deleteConnect() will show more detail

>>
>> Finally - C is fun, keep going. And all the best
>>
>> marc
>>
>