ENOENT error occurs while issueing execlp command

/************************************************************************
*
* TEST NAME: setrlimitd_su.c
*
* PURPOSE: To verify the soft (rlim_cur) and hard (rlim_max) limit
* of process RLIMIT_DATA resources correctly inherited by
* the exec() system call.
*
* RESULT: function call should pass (exit 0) otherwise exit with
* EWRONGLIM for incorrect limit (check d.txt for errors).
*
* COMMENTS: Test setup is similarly to the original setrlimit_su.c.
* The algorithm is formulated based upon the defects found
* by the VSU standard tests. It exec'es ./dlim prog file.
*
*************************************************************************/
#include <sys/wait.h>
#include <sys/resource.h>
#include <sys/fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/mman.h>
#include <inttypes.h>
#include "defs.h"
void func(id_t, rlim_t, rlim_t, rlim_t, rlim_t);
char cur_arg[NUM_CHBUFS];
char max_arg[NUM_CHBUFS];
struct rlimit dlim; 
rlim_t org_dcur, org_dmax, dcur, dmax;
main()
{
if (getuid()) {
fprintf(stderr, "ERROR: test must be run as root\n");
exit(11);
}
getrlimit(RLIMIT_DATA, &dlim);
org_dcur = dlim.rlim_cur;
org_dmax = dlim.rlim_max;
/* Decrement limits by 1. */
dcur = org_dcur-1;
dmax = org_dmax-1;
printf("Original RLIMIT_DATA values:\n");
printf("----------------------------\n");
printf("dlim.rlim_cur = 0x%lx\n", org_dcur);
printf("dlim.rlim_max = 0x%lx\n", org_dmax);
printf("\n");
printf("\nTest: Lower cur, max RLIMIT_DATA by 1, then call exec\n");
fflush(stdout);
/* (cur,max) (cur,max) */
/* uid, init limits, new limits */
func( 1, org_dcur, org_dmax, dcur, dmax);
exit(0);
}
void
func( id_t id, /* The uid to use when running this test (0/non-0) */
rlim_t org_cur, /* The values at the beginning of the test */
rlim_t org_max,
rlim_t cur, /* The values to set */
rlim_t max
)
{
pid_t child, g_child;
int status;
int rv;
struct rlimit lim, ret_lim;
int i;
 
int ret=0;
ret=execlp("dlim", "dlim",ultostr(cur,16), ultostr(max,16), NULL);
printf("return valu is %d\n",ret);
 
/*
* Set up a child to do all the work because the child has to 
* change uids
*/
if ((child= fork()) == (pid_t)-1) {
perror("ERROR: fork");
printf("errno = %d\n", errno);
exit(1);
}
else if (child) { /*parent*/
waitpid(child, &status, 0);
if (WEXITSTATUS(status)) /* If test failed */
exit(WEXITSTATUS(status));
if (WIFSIGNALED(status)) /* If test died from signal */
raise(WTERMSIG(status)); /*We should get it too */
}
else { /*child, which does all the work */
lim.rlim_cur = org_cur;
lim.rlim_max = org_max;
printf("===============================\n");
printf("| Begin test with RLIMIT_DATA |\n");
printf("===============================\n");
printf("Setting original setrlimit ");
printf("org_cur=0x%lx org_max=0x%lx\n", org_cur, org_max);
if (setrlimit(RLIMIT_DATA, &lim)== -1) {
perror("ERROR: 1st setrlimit, RLIMIT_DATA");
printf("errno = %d\n", errno);
exit(2);
}

if ( (id) && (setuid(id) == -1) ) {
perror("ERROR: setuid failed");
printf("errno = %d\n", errno);
exit(3);
}
printf("Setting new lowered setrlimit ");
printf("cur=0x%lx max=0x%lx\n", cur, max);
fflush(stdout);
lim.rlim_cur = cur;
lim.rlim_max = max;
rv = setrlimit(RLIMIT_DATA, &lim);
if (rv != 0) {
perror("ERROR: Unexpected failure");
printf("errno = %d\n", errno);
exit(4);
}

/*
*Now we make sure the call did the right thing 
*/
if (getrlimit(RLIMIT_DATA, &ret_lim) == -1) {
perror("ERROR: getrlimit failed");
printf("errno = %d\n", errno);
exit(5);
}
printf("After new setrlimit, getrlimit returned ");
printf("cur=0x%lx max=0x%lx\n", ret_lim.rlim_cur, ret_lim.rlim_max);
if ((ret_lim.rlim_cur != cur) || (ret_lim.rlim_max != max)) { 

perror("ERROR: wrong limits returned by getrlimit\n");
printf("errno = %d\n", errno);
exit(6);
} 
/* 
* We decrement the original cur and max of RLIMIT_DATA 
* by one and try to exec ./dlim executable file to verify 
* if the lowered limits are retained across the execlp() call.
* 
*/
 
printf("Calling exec to test for setrlimit of RLIMIT_DATA\n");
printf("cur=0x%lx max=0x%lx)\n", cur, max);

/* 
printf("Now, execlp(\"./dlim\")\n");
printf("printing... execlp(\"./dlim\")\n");
printf(" %s, %s\n", ultostr(cur,16), ultostr(max,16));
*/
fflush(stdout);
/*
* Set up a grandchild to perform the exec call.
*
*/
if ((g_child=fork()) == (pid_t)-1) {
perror("ERROR: fork");
exit(11);
}
else if (g_child) { /*parent*/
waitpid(g_child, &status, 0);
if (WEXITSTATUS(status)) { /* If test failed */
if (WEXITSTATUS(status)==EWRONGLIM)
fprintf(stderr, "ERROR: exec'ed wrong limits -- please check d.txt\n");
else if (WEXITSTATUS(status)==EWRONGARG)
fprintf(stderr, "ERROR: incorrect number of args passed into exec'ed prog.\n");
else
fprintf(stderr, "ERROR: after exec'ed\n"); 
exit(WEXITSTATUS(status));
}
if (WIFSIGNALED(status)) /* If test died from signal */
raise(WTERMSIG(status)); /*parent gets it too */
printf("\n");
fflush(stdout);
exit(0);
}
else { /* g_child will do the exec and NOT return */
rv = execlp("dlim", "dlim", 
ultostr(cur,16), ultostr(max,16), NULL); 
if (rv == -1) {
perror("ERROR: execlp(./dlim) failed");
printf("errno = %d\n", errno);
exit(12);
}
else {
perror("ERROR: shouldn't be returned here from the exec() call!");
printf("errno = %d\n", errno);
exit(13);
}
}
printf("\n");
fflush(stdout);
exit(0);
}
}
 

Hi,

I am getting error at execlp command.Error is ENOENT.For understanding the codeflow copied entire code.

Below is the output for the above code..

Test: Lower cur, max RLIMIT_DATA by 1, then call exec
return valu is -1

| Begin test with RLIMIT_DATA |

Setting original setrlimit org_cur=0x100000000 org_max=0x100000000
Setting new lowered setrlimit cur=0xffffffff max=0xffffffff
After new setrlimit, getrlimit returned cur=0xffffffff max=0xffffffff
Calling exec to test for setrlimit of RLIMIT_DATA
cur=0xffffffff max=0xffffffff)
ERROR: execlp(./dlim) failed: No such file or directory
errno = 2
ERROR: after exec'ed
Original RLIMIT_DATA values:
----------------------------
dlim.rlim_cur = 0x100000000
dlim.rlim_max = 0x100000000

Please let me know what is the issue here..
Looks like dlim executable is not available..

Thanks in Advance,
Mansa

ENOENT means one of:

  1. the file does not exist in the path you specify
  2. one of the components of the path you specify does not exist

I would consider NOT using a relative path to dlim like you just did. Create a full file specification -- /my/directory/delim