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 7822637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:58:36+00:00 2026-06-02T07:58:36+00:00

I basically am running into a very odd situation in a system call that

  • 0

I basically am running into a very odd situation in a system call that I am writing. I want to check some values if they are the same return -2 which indicates a certain type of error has occurred. I am using printk() to print the values of the variables right before my “else if” and it says that they are equal to one another but yet the conditional is not being executed (i.e. we don’t enter the else if) I am fairly new to working in the kernel but this seems very off to me and am wondering if there is some nuance of working in the kernel I am not aware of so if anyone could venture a guess as to why if I know the values of my variables the conditional would not execute I would really appreciate your help

//—————————————//

/*  sys_receiveMsg421()
     Description:
    - Copies the first message in the mailbox into <msg>
*/
asmlinkage long sys_receiveMsg421(unsigned long mbxID, char *msg, unsigned long N)
{

int result = 0;
int mboxIndex = checkBoxId(mbxID);
int msgIndex = 0;

//acquire the lock
down_interruptible(&sem);

//check to make sure the mailbox with <mbxID> exists
if(!mboxIndex)
{
    //free our lock
    up(&sem);
    return -1;
}

else
    mboxIndex--;

printk("<1>mboxIndex = %d\nNumber of messages = %dCurrent Msg = %d\n",mboxIndex, groupBox.boxes[mboxIndex].numMessages, groupBox.boxes[mboxIndex].currentMsg );

//check to make sure we have a message to recieve

-----------CODE NOT EXECUTING HERE------------------------------------------------
if(groupBox.boxes[mboxIndex].numMessages == groupBox.boxes[mboxIndex].currentMsg)
{
    //free our lock
    up(&sem);   
    return -2;
}
//retrieve the message
else
{
     //check to make sure the msg is a valid pointer before continuing
    if(!access_ok(VERIFY_READ, msg, N * sizeof(char)))
    {
        printk("<1>Access has been denied for %lu\n", mbxID);
        //free our lock
        up(&sem);
        return -1;
    }
    else
    {
        //calculate the index of the message to be retrieved            
        msgIndex = groupBox.boxes[mboxIndex].currentMsg;    

        //copy from kernel to user variable     
        result = copy_to_user(msg, groupBox.boxes[mboxIndex].messages[msgIndex], N);

        //increment message position
        groupBox.boxes[mboxIndex].currentMsg++;

        //free our lock
        up(&sem);

        //return number of bytes copied
        return (N - result);
    }
}
}

UPDATE: Solved my problem by just changing the return value to something else and it works fine very weird though

  • 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-06-02T07:58:39+00:00Added an answer on June 2, 2026 at 7:58 am

    Please remember to use punctuation; I don’t like running out of breath while reading questions.

    Are you sure the if block isn’t being entered? A printk there (and another in the corresponding else block) would take you one step further, no?

    As for the question: No, there isn’t anything specific to kernel code that would make this not work.

    And you seem to have synchronization covered, too. Though: I see that you’re acquiring mboxIndex outside the critical section. Could that cause a problem? It’s hard to tell from this snippet, which doesn’t even have groupBox declared.

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

Sidebar

Related Questions

I've ran into a strange situation. I'm writing some test cases for my program.
EDIT: I am basically running into the following documented issue . I am using
I am creating a little testing component and am running into a problem Basically
I basically have a unix process running and it is doing some heavy processing
I'm running a loop basically that will make an array that contains a million
I've got a socket server running (it's something that's basically like a chat server).
I'm attempting to do something very odd, and I'm having some luck, but am
I am fairly proficient in CSS but now I am running into a very
I'm in need of a distributed file system that must scale to very large
I'm running into a number of problems creating an effect very similar to the

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.