Re:problem with getting user name
Answered: amber (solid confidence) — Message quotes the full original question (4GL C-function core dump getting the user ID after upgrading 1.10->4.1), correctly diagnoses the bug (POPQUOTE called with no argument) and offers a simpler SQL-only alternative; not confirmed by the asker.
Advisory only.
Posted in 1992
>> From uunet!rmy.emory.edu!informix-list-owner Tue Jan 14 20:34:47 1992
>> From: uunet!ulysses.att.com!jwt
>> To: informix-list@rmy.emory.edu
>>
>> I have some problem on my INFORMIX-4GL upgrade,
>> we got the new 4.1 from INFORMIX last month, we had the 1.10 before.
>>
>> I have a C function that 4GL program called to get the user ID, it works
>> fine on the 1.10, but when I run it on the 4.1, it gets core dump, the
>> message is "Memory fault(coredump)"
>>
>> My C program is
>>
>> #include <sys/types.h>
>> #include <pwd.h>
>> get_userid()
>> {
>> struct passwd *user_info, *getpwuid();
>> char user_id[11];
>> int uid;
>>
>> popquote(user_id,11);
This is a bug right here. You are trying to pop a character parameter
but you haven't passed any. I'm surprised this didn't fail in 1.10.
>> uid = getuid();
>> user_info = getpwuid(uid);
Unless getpwuid() allocates its own passwd structure, this could be a problem.
>> strcpy(user_id, user_info->pw_name);
>> retquote(user_id);
>> return(1);
>> }
>>
>> my 4gl program is
>>
>> database cna
>> define user_id char(11)
>>
>> main
>> call get_userid() returning user_id
Since you have a database open, this is a lot easier:
SELECT UNIQUE user INTO user_id FROM systables
Then, you don't even need a C function.
>> display user_id
>> end main
>>
>> My C program is not good, someone else wrote it for me,
>> maybe there are other ways to get user ID, or there is some function
>> in 4.1 that I can use to get the user ID, can someone please help me.
>>
>> Thanks,
>>
>> Jim Tseng
>> jwt@ulysses.att.com
Hope this helps.
--
Alan Denney # aland@informix.com # {pyramid|uunet}!infmx!aland
"Now they'll have this "Chunnel" thing, parallel tunnels running
between England and France. Let's see. The English drive on the
left side, and the French drive on the right side. Hmmmmm.
That's going to be one *busy* lane!" - John Mendoza