Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3840720
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:33:44+00:00 2026-05-19T15:33:44+00:00

I’m a C newbie. My eventual goal is to create an Apache module that

  • 0

I’m a C newbie. My eventual goal is to create an Apache module that returns the Apache user account’s crontab as JSON.

Baby steps first though. I’ve successfully followed tutorials at the two following locations to output “hello world” and variations thereof from an Apache module (and I actually own Nick Kew’s book):

  • http://www.cb1inc.com/2007/12/24/creating-a-hello-world-apache-module-with-kdevelop-on-ubuntu/
  • http://www.theregister.co.uk/2006/10/03/apache_modules/

I’ve modified the examples slightly to output JSON as follows:

ap_rputs("{'hello': {'to': 'world', 'from': '?'}}", r);

I’d like to substitute the ‘?’ above with output from the Linux system’s ‘whoami’ command (eventually I want to run the linux command ‘crontab -lu username’). As a C newbie though I am overwhelmed by the choices as to how to go about this, I’ve tried a few things, and don’t seem to be close to getting anything right. I do seem to be able to trap the output from whoami, or at least my code compiles and runs 😉

FILE *sysp = popen("whoami","r");

But am I even doing the above right? And what is a good next step? I thought I might try to determine the length of the output from above, then create a char array of the same length, rewind the file handle, and grab the output. But I don’t seem to be obtaining the length properly, and maybe this is a sub-optimal approach? When I run the following (I’ve left out a couple of lines I know might be necessary, i.e. rewind, fclose) the output I get is -1:

fseek(sysp, 0L, SEEK_END);
long len = ftell(sysp);
char buf[2];
sprintf(buf, "%d", (int)len);
ap_rputs(buf, r);

Any pointers specifically as to how to better approach outputting the result from the system command “whoami” would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:33:45+00:00Added an answer on May 19, 2026 at 3:33 pm

    The FILE * in this case refers to a pipe, which may not really be seekable. Ideally, you should get the information you are looking for directly from the system, rather than invoking an external program; I think the getuid() and getpwent() functions will come in handy here.

    As getpwent() may block (just as your method using popen(), it is not safe to use your module with any MPM that does not use at least a single thread per request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.