- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- For C experts
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 01:08 AM
05-04-2004 01:08 AM
For C experts
I am having a problem with a small C program (extract from a bigger program).
It compiles nicely but at execution, it core dumps.
I use gcc3.2.2 and HP-UX B.11.00 A to compile it.
This is the program:
"
#include
#include
#include
#include
#include
char * sh_unix_getUIDdir (int level, uid_t uid)
{
struct passwd * tempres;
int status = 0;
uid_t seuid, sruid;
seuid = geteuid();
sruid = getuid();
printf("name: %s\n",tempres->pw_name);
printf("seuid: %i\n",seuid);
printf("sruid: %i\n",sruid);
}
main()
{
char * p;
p = sh_unix_getUIDdir (2,0);
}
"
It coredumps on the "printf("name: %s\n",tempres->pw_name);" statement.
It don't understand why.
When I compile it wit HP Ansi C, it does not coredump but there is no value for "tempres->pw_name"
When I more all the code into the main loop, it works fine.
I am not all familiar with C so this might be normal behaviour in C.
I am however having no problem compiling the same thing with the same gcc version on solaris or tru64 (or HP-UX 10.20)
Any help really appreciated.
Kris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 01:17 AM
05-04-2004 01:17 AM
Re: For C experts
something like
----
char *goofy;
goofy=tempres->pw_name;
printf ("....",goofy);
----
Look at the idea, not at the code! I may be syntax-wrong ;-)
Peace, r.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 01:18 AM
05-04-2004 01:18 AM
Re: For C experts
Stupid me.
Kd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 01:20 AM
05-04-2004 01:20 AM
Re: For C experts
However, you have declared a pointer to a passwd structure called tempres. However, this pointer doesn't point at anything. Therefore, when you print it it runs across a bit of random memory until it falls over in a nasty heap.
Unless I misread this horribly, you need to make "tempres" point at a real password entry using something like getpwent().
Have a look at "man getpwent"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 01:21 AM
05-04-2004 01:21 AM
Re: For C experts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 02:19 AM
05-04-2004 02:19 AM
Re: For C experts
I'll also point out another very common error that often works by accident.
char *silly_function(int n)
{
char s[80];
(void) sprintf(s,"Silly %d",n);
return(s);
} /* silly_function */
int main()
{
char *p;
p = sillly_function(100);
(void) printf("Silly: %s\n",p);
return(0);
} /* main */
This will compile and often execute perfectly but crash on other platforms or if changes are made to the code. Why? Rather than telling you why, I'll give you the fix and the why is left as an exercise.
Change the declaration in silly_function from
char s[80];
to
static char s[80];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 02:24 AM
05-04-2004 02:24 AM
Re: For C experts
However, the code example comes from a bigger program (not written by me) and it does return the correct information.
The problem I have is that the "tempres = getpwuid(uid);" call fails with an error code of 215.
I don't see why and I don't find the info what errno 215 means for that call.
I see no reason why this call would fail.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 02:35 AM
05-04-2004 02:35 AM
Re: For C experts
Still looking at A.Clay's teaser.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 02:38 AM
05-04-2004 02:38 AM
Re: For C experts
That's why I wrote that small program mentioned above but 'unfortunately' it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2004 02:54 AM
05-04-2004 02:54 AM
Re: For C experts
The binary was compiled to produce a static binary.
When I removed the option, it compiled nicely.
The meaning of the error code gave me a hint.
It is strange however that at link time it did not complain
Kris