HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Problems with exec families
Operating System - Linux
1829463
Members
1608
Online
109991
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
03-06-2001 08:44 AM
03-06-2001 08:44 AM
Problems with exec families
i wrote this program
------------------------
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
char cadena[2048];
sprintf(cadena,"%s",argv[1]);
cadena[strlen(cadena)]='\0';
printf("finger %s\n",cadena);
if (execl("/usr/bin/","finger",cadena)<0)
{
perror("Creacion:");
}
}
-----------------------
but when i running this is the result
[jruiz@dns cgi]$ a.out jruiz
finger jruiz
Creacion:: Permission denied
[jruiz@dns cgi]$
-------------------------
what is the problem i know i have permition to see myself, is the same problem when the root own the program
------------------------
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
char cadena[2048];
sprintf(cadena,"%s",argv[1]);
cadena[strlen(cadena)]='\0';
printf("finger %s\n",cadena);
if (execl("/usr/bin/","finger",cadena)<0)
{
perror("Creacion:");
}
}
-----------------------
but when i running this is the result
[jruiz@dns cgi]$ a.out jruiz
finger jruiz
Creacion:: Permission denied
[jruiz@dns cgi]$
-------------------------
what is the problem i know i have permition to see myself, is the same problem when the root own the program
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2001 09:40 AM
03-06-2001 09:40 AM
Re: Problems with exec families
The first arguement for execl is the pathname of a *FILE* which is to be executed. This means you need to write
if (execl("/usr/bin/finger","finger",cadena)<0) {
/* ... */
}
Also, what is the purpose of the line
cadena[strlen(cadena)]='\0';
If you can get string length, it is properly null-terminated. If it is not terminated or terminated, say, at 2040, this line is not going to help.
Regards,
Fellix
if (execl("/usr/bin/finger","finger",cadena)<0) {
/* ... */
}
Also, what is the purpose of the line
cadena[strlen(cadena)]='\0';
If you can get string length, it is properly null-terminated. If it is not terminated or terminated, say, at 2040, this line is not going to help.
Regards,
Fellix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2001 12:06 AM
03-07-2001 12:06 AM
Re: Problems with exec families
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
char cadena[2048];
sprintf(cadena,"%s",argv[1]);
cadena[strlen(cadena)]='\0';
printf("finger %s\n",cadena);
/* the first parameter to any exec is
* the name/path of the program you wish to
* execute, thus:
* execl("/usr/bin/finger", "finger", cadena);
*/
if (execl("/usr/bin/","finger",cadena)<0)
{
perror("Creacion:");
}
}
Now ... as for argv[0], which is the second parameter, this is actually passed as a the zeroth argument to the program. While with something like finger it is not evident what the use may be, but some software programs use the zeroth argumnet rather niftily (is that a word yet?)
For example, gzip examines its own name (i.e, contents of argv[0]) and figures out if it is actually being called as 'gzip' or 'gunzip' and accordingly zips or unzips the subsequent arguments.
For instance, the attached example implements a slightly different version of the system utils 'basename' and 'dirname'
#include
#include
#include
#include
int main(int argc, char *argv[])
{
char cadena[2048];
sprintf(cadena,"%s",argv[1]);
cadena[strlen(cadena)]='\0';
printf("finger %s\n",cadena);
/* the first parameter to any exec is
* the name/path of the program you wish to
* execute, thus:
* execl("/usr/bin/finger", "finger", cadena);
*/
if (execl("/usr/bin/","finger",cadena)<0)
{
perror("Creacion:");
}
}
Now ... as for argv[0], which is the second parameter, this is actually passed as a the zeroth argument to the program. While with something like finger it is not evident what the use may be, but some software programs use the zeroth argumnet rather niftily (is that a word yet?)
For example, gzip examines its own name (i.e, contents of argv[0]) and figures out if it is actually being called as 'gzip' or 'gunzip' and accordingly zips or unzips the subsequent arguments.
For instance, the attached example implements a slightly different version of the system utils 'basename' and 'dirname'
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP