Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posix.getpid() doesn't accept any arguments. #231

Closed
karlp opened this issue Aug 25, 2015 · 11 comments
Closed

posix.getpid() doesn't accept any arguments. #231

karlp opened this issue Aug 25, 2015 · 11 comments
Assignees

Comments

@karlp
Copy link

karlp commented Aug 25, 2015

In v32, you could use posix.getpid("pid") and posix.getpid("ppid").
in v33, you can only use posix.getpid() and posix.getppid()

However, the NEWS file for v33 says, under "bugs fixed" "posix.getpasswd, posix.getpid, posix.pathconf, posix.stat, posix.statvfs, posix.sysconf and posix.times process a single table argument with a list of types correctly."

v33 (v33.2.1 to be specific) does not allow passing any arguments, table or string or otherwise, into posix.getpid().

I'm fine with it not being backward compatible, but how is it meant to behave? Is there no longer any method to get the full table?

Also, the fact that these are available as posix.getxxx is not documented. They are only described as under posix.unistd.xxxx

@gvvaughan gvvaughan self-assigned this Aug 26, 2015
@gvvaughan
Copy link
Contributor

Hi Karl,

Thanks for the report. I can't reproduce your issue, even if I downgrade to v33.2.1:

$ luarocks remove luaposix
$ luarocks install luaposix 33.2.1
...
luaposix 33.2.1-1 is now built and installed in /usr/local (license: MIT/X11)
$ lua
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> =require'posix'.version
posix for Lua 5.2 / luaposix 33.2.1
> tostring=require'std'.tostring
> getpid=require'posix'.getpid
> =getpid()
{egid=20,euid=504,gid=20,pgrp=58875,pid=58875,ppid=8578,uid=504}
> =getpid'pid'
58875
> =getpid{'pid'}
58875

This also works with latest master.

There is no documentation for that behaviour, because it is provided purely for backwards compatibility so as not to surprise clients that use the old APIs. As such it is not documented, in order to encourage the use of the faster new thin wrappers for the functions (getpid etc) from unistd.h, which are documented here:

http://luaposix.github.io/luaposix/modules/posix.unistd.html

And used like this:

$ luarocks install luaposix
...
luaposix 33.3.1-1 is now built and installed in /usr/local (license: MIT/X11)
$ lua
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> =require'posix'.version
posix for Lua 5.2 / luaposix 33.3.1
> unistd=require'posix.unistd'
> =unistd.getpid()
62182
> =unistd.getppid()
8578

Cheers,
Gary

@karlp
Copy link
Author

karlp commented Aug 26, 2015

I wish it were that easy :)

Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio (double int32)
> =require'posix'.version
posix for Lua 5.1 / luaposix 33.2.1
>  getpid=require'posix'.getpid
> =getpid()
2128
> =getpid'pid'
stdin:1: bad argument #1 to 'getpid' (no more than 0 arguments expected, got 1)
stack traceback:
    [C]: in function 'getpid'
    stdin:1: in main chunk
    [C]: ?
> =getpid{'pid'}
stdin:1: bad argument #1 to 'getpid' (no more than 0 arguments expected, got 1)
stack traceback:
    [C]: in function 'getpid'
    stdin:1: in main chunk
    [C]: ?
> 

Is it possible that luaposix has been mis-packaged in this case? Any tips on how I could check whether luaposix is installed correctly?

@gvvaughan
Copy link
Contributor

Looks like you're missing the lua loader that puts all the backward compatibility shims in place, or your LUA_PATH is missing their install location, or you are picking up bits from mismatched releases somehow If posix.getpid is a C function (can't string.dump it) or is equal to the function at require "posix.unistd".getpid, that would confirm. Maybe look at the directories from print(package.path) in order to see what posix.lua is found and whether it is loading the shims from posix/deprecated.lua and posix/compact.lua.

HTH

@karlp
Copy link
Author

karlp commented Aug 27, 2015

Yup, the openwrt packaging explicitly excludes the compat and deprecated. (And worse, it was even myself that suggested we could do that, when we saw how big they were)

Thanks for looking into this, and I'm sorry for the wild goose chase.

@gvvaughan
Copy link
Contributor

No problem, thanks for letting me know what the underlying issue was.

For the record, I think you have taken the right approach, because you have control over all the client code, you can write it to take advantage of the latest and greatest APIs, and jettison all the cruft for supporting slow adopters too :-)

@LinuxOnTheDesktop
Copy link

Might I work necromancy on this thread to say: I'm confused - does luaposix allow one to see whether an arbitrary string has a coresponding 'pid', as Linux's pidof does, or does it not? If it does not, then that seems a rather severe lack of functionality. (I have looked through the luaposix documentation but it has not enlightened me.)

@karlp
Copy link
Author

karlp commented Apr 8, 2021

@LinuxOnTheDesktop pidof isn't actually a posix function at all, so it's completely out of scope.

@LinuxOnTheDesktop
Copy link

@karlp: good point. Surely though luaposix or lua itself provides some fairly straightforward way of checking whether a process is running?

@karlp
Copy link
Author

karlp commented Apr 8, 2021

it may, but it's absolutely not the right place to talk about it on this ticket.

@LinuxOnTheDesktop
Copy link

Right. I can't seem to find a luaposix IRC or forum, though.

@gvvaughan
Copy link
Contributor

You can start a thread on the regular Lua mailing list if you’d like. There are plenty of ways to get at Linux-only C APIs from Lua, but luaposix is not among them :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants