openct shutdown

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

openct shutdown

Paulo Soto de Miranda
Hi

I'm developing a graphic user interface to opensc using libp11 and
libopenct.
One of the functions of this interface is start and stop the openct. But
i'm having problems to shutdown the openct rightly. To do so i using the
source code of the openct-control tool. This code don't relese all the
resource loaded. If i start the process of the gui, initialize the
openct, finalize openct and stop the process of the gui, the ifdhandler
process stop. But if i start the process of the gui; inicialize and stop
openct several times and stop the gui process,the ifdhandler processes
don't stop. I think that some openct resources loaded are unloaded only
when the process that launched then stop.
Somebody can help me ?
Sorry about the english erros :) ...

Paulo Soto de Miranda

_______________________________________________
opensc-devel mailing list
[hidden email]
http://www.opensc.org/cgi-bin/mailman/listinfo/opensc-devel
Reply | Threaded
Open this post in threaded view
|

Re: openct shutdown

Andreas Jellinghaus-2
Hi Paulo,

sorry for the late reply.
 
> I'm developing a graphic user interface to opensc using libp11 and
> libopenct.

hmm, I wonder: why are you using libopenct? isn't libp11 enough?
what is missing?

> One of the functions of this interface is start and stop the openct. But
> i'm having problems to shutdown the openct rightly. To do so i using the
> source code of the openct-control tool.

hmm, openct-control needs to run as root. if you could call it via
a shell, your application could run as normal, user, and then ask
for the root password (only when the user calls those functions).

> This code don't relese all the  
> resource loaded. If i start the process of the gui, initialize the
> openct, finalize openct and stop the process of the gui, the ifdhandler
> process stop.

hmm, could well be, maybe the code is not 100% clean. in command line tools
we can do that, because we know the process is short lived, and exit() will
cleanup everything. but of course you are right, it is better to clean up
those issues. maybe you can post some details? would be nice if I could
reproduce your findings with opensc-control code (if needed plus small
change / or in gdb?).

> But if i start the process of the gui; inicialize and stop  
> openct several times and stop the gui process,the ifdhandler processes
> don't stop. I think that some openct resources loaded are unloaded only
> when the process that launched then stop.

hmm, the shutdown code is extremly simple: look at all ifdhandlers / pid
files and send them a sigterm. I think not much can go wrong here.

but: you might experience delays. for example it could take a few seconds
till the processes terminate, simply because they poll() and earlier
linux had a bug where the poll() did not return before it timed out.

or maybe you where running your app as user?
if you send a sigterm signal to the ifdhandler process, which runs as root,
it won't reach it's target. instead you will get the EPERM error code
from kill() (hmm, openct-control doesn't check the error code a lot,
your code should do that in detail).

Regards, Andreas
_______________________________________________
opensc-devel mailing list
[hidden email]
http://www.opensc.org/cgi-bin/mailman/listinfo/opensc-devel
Reply | Threaded
Open this post in threaded view
|

Re: openct shutdown

Paulo Soto de Miranda


Hi Andreas,

Andreas Jellinghaus wrote:

>Hi Paulo,
>
>sorry for the late reply.
>
>  
>
>>I'm developing a graphic user interface to opensc using libp11 and
>>libopenct.
>>    
>>
>
>hmm, I wonder: why are you using libopenct? isn't libp11 enough?
>what is missing?
>
>  
>
One of the functions of this interface is start and stop the smart card
reader. Libp11 doesn't do this, so I need to call libopenct functions.
But up against this problems and becouse the aplication must run as a
root process, i decided to delete this function from the project.

I've founded one problem using libp11 with pcscd. If i load libp11
module and then disconnect the smart card reader, the pcscd crash. I
don't test this with openct, but i will do.

>>One of the functions of this interface is start and stop the openct. But
>>i'm having problems to shutdown the openct rightly. To do so i using the
>>source code of the openct-control tool.
>>    
>>
>
>hmm, openct-control needs to run as root. if you could call it via
>a shell, your application could run as normal, user, and then ask
>for the root password (only when the user calls those functions).
>
>  
>
>>This code don't relese all the  
>>resource loaded. If i start the process of the gui, initialize the
>>openct, finalize openct and stop the process of the gui, the ifdhandler
>>process stop.
>>    
>>
>
>hmm, could well be, maybe the code is not 100% clean. in command line tools
>we can do that, because we know the process is short lived, and exit() will
>cleanup everything. but of course you are right, it is better to clean up
>those issues. maybe you can post some details? would be nice if I could
>reproduce your findings with opensc-control code (if needed plus small
>change / or in gdb?).
>
>  
>
Just copy and past the functions of opencttool.c and call several times
start and stop. After call "ps -A" via a shell and you will see several
ifdhandler process still running.

>> But if i start the process of the gui; inicialize and stop  
>>openct several times and stop the gui process,the ifdhandler processes
>>don't stop. I think that some openct resources loaded are unloaded only
>>when the process that launched then stop.
>>    
>>
>
>hmm, the shutdown code is extremly simple: look at all ifdhandlers / pid
>files and send them a sigterm. I think not much can go wrong here.
>
>but: you might experience delays. for example it could take a few seconds
>till the processes terminate, simply because they poll() and earlier
>linux had a bug where the poll() did not return before it timed out.
>
>or maybe you where running your app as user?
>if you send a sigterm signal to the ifdhandler process, which runs as root,
>it won't reach it's target. instead you will get the EPERM error code
>from kill() (hmm, openct-control doesn't check the error code a lot,
>your code should do that in detail).
>  
>
I'm running my application as user.

>Regards, Andreas
>  
>
thanks for your attention.

Paulo
_______________________________________________
opensc-devel mailing list
[hidden email]
http://www.opensc.org/cgi-bin/mailman/listinfo/opensc-devel
Reply | Threaded
Open this post in threaded view
|

Re: openct shutdown

Andreas Jellinghaus-2
On Wednesday 28 September 2005 02:57, Paulo wrote:
> I'm running my application as user.

ok, in that case it simply won't work.
you need to run it as root, or use a root
wrapper - for example run "su /etc/init.d/openct stop",
or sudo or something like that.

could you run your app once as root?
then it should work all fine.
but in the end that is not the prefered way.

the "ifdhandler" process needs to run as root,
as only root can use those ioctl() syscalls
on the usb devices, you can't change that.
ifdhandlers for serial smart card readers
could run as other users, but by default they
also run as root.

Regards, Andreas
_______________________________________________
opensc-devel mailing list
[hidden email]
http://www.opensc.org/cgi-bin/mailman/listinfo/opensc-devel
Reply | Threaded
Open this post in threaded view
|

Re: openct shutdown

Ludovic Rousseau
On 28/09/05, Andreas Jellinghaus <[hidden email]> wrote:
> the "ifdhandler" process needs to run as root,
> as only root can use those ioctl() syscalls
> on the usb devices, you can't change that.

I guess you can change the permission on the USB device
(/proc/bus/usb/xxx/yyy in Linux) so a normal user can
read/write/ioctl on them.

At least I can run my CCID driver as a normal user after a correct
chmod on the correct device.

Of course it is a bit difficult since the device file name will change
after each device physical connection.

Bye,

--
  Dr. Ludovic Rousseau
 For private mail use [hidden email] and not "big brother" Google
_______________________________________________
opensc-devel mailing list
[hidden email]
http://www.opensc.org/cgi-bin/mailman/listinfo/opensc-devel
Reply | Threaded
Open this post in threaded view
|

Re: openct shutdown

Ludovic Rousseau
In reply to this post by Paulo Soto de Miranda
On 28/09/05, Paulo <[hidden email]> wrote:
> I've founded one problem using libp11 with pcscd. If i load libp11
> module and then disconnect the smart card reader, the pcscd crash. I
> don't test this with openct, but i will do.

Can you give me a bit more information please?
- what pcsc-lite version are you using?
- what reader driver are you using?

If you are not yet using pcsc-lite 1.2.9-beta8 test it and try to
reproduce the bug.

Thanks,

--
  Dr. Ludovic Rousseau
 For private mail use [hidden email] and not "big brother" Google
_______________________________________________
opensc-devel mailing list
[hidden email]
http://www.opensc.org/cgi-bin/mailman/listinfo/opensc-devel
Reply | Threaded
Open this post in threaded view
|

Re: openct shutdown

Andreas Jellinghaus-2
In reply to this post by Paulo Soto de Miranda
Hi,

if you are running kde, you might want to use
"kdesu /etc/init.d/openct start".

kdesu opens up a nice gui window, asks for the
password and then runs the program as root.

if you are using gnome, I hope they have something
similar.

that would be quite easy, I guess.
most important you don't need to re-invent that
wheel :)

good luck!

Andreas
_______________________________________________
opensc-devel mailing list
[hidden email]
http://www.opensc.org/cgi-bin/mailman/listinfo/opensc-devel
Reply | Threaded
Open this post in threaded view
|

Re: openct shutdown

Peter Stuge
In reply to this post by Ludovic Rousseau
On Wed, Sep 28, 2005 at 09:34:00AM +0200, Ludovic Rousseau wrote:
> Of course it is a bit difficult since the device file name will change
> after each device physical connection.

udev/sysfs/hotplug makes this pretty simple, you can use things like
device serial number in order to create named symlinks to the usb
device files.


//Peter
_______________________________________________
opensc-devel mailing list
[hidden email]
http://www.opensc.org/cgi-bin/mailman/listinfo/opensc-devel
Reply | Threaded
Open this post in threaded view
|

Re: openct shutdown

Paulo Soto de Miranda
In reply to this post by Andreas Jellinghaus-2
When i was using libopenct, i was running my application as root user. But now
i'm not using libopenct anymore.

Quoting Andreas Jellinghaus <[hidden email]>:

> On Wednesday 28 September 2005 02:57, Paulo wrote:
>> I'm running my application as user.
>
> ok, in that case it simply won't work.
> you need to run it as root, or use a root
> wrapper - for example run "su /etc/init.d/openct stop",
> or sudo or something like that.
>
> could you run your app once as root?
> then it should work all fine.
> but in the end that is not the prefered way.
>
> the "ifdhandler" process needs to run as root,
> as only root can use those ioctl() syscalls
> on the usb devices, you can't change that.
> ifdhandlers for serial smart card readers
> could run as other users, but by default they
> also run as root.
>
> Regards, Andreas
>



_______________________________________________
opensc-devel mailing list
[hidden email]
http://www.opensc.org/cgi-bin/mailman/listinfo/opensc-devel