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

  • Home
  • SEARCH
  • 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 8521135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:43:58+00:00 2026-06-11T06:43:58+00:00

I am working on a rather complex C++ code which performs the following operation

  • 0

I am working on a rather complex C++ code which performs the following operation as standard user

fd = open("/dev/port",O_WRONLY);
...
lseek(fd, 0x2E,SEEK_SET);
...
write(fd,&buf,1);

I get a ‘Operation not permitted’ error on opening the file, despite having chmodded the file.

crwxrwxrwx 1 root kmem 1, 4 Sep 12 14:32 /dev/port

I know of security issues with chmodding /dev/port, but as far as we’re concerned the system will run on a closed LAN.


To make it easier, this:

using namespace std;
int main(int argc, char *argv[])
{
  int fd=-1;

  //  fd1=open("/dev/port",O_RDWR|O_NDELAY);
  vector<string> fnames;
  fnames.push_back("/dev/port");
  fnames.push_back("/dev/tty0");

  string fname;


  for(int i=0;i<fnames.size();i++)
    {
      fname = fnames[i];
      fd=open(fname.c_str(),O_RDWR | O_NDELAY);
      if(fd<0)
    {
      cout << fname << " "  << fd << endl;
      cout << fname << " "  << strerror(errno) << endl;
    }
      else
    {
      cout << "Open ok: " << fname << endl;
    }
    }


  return 0;
}

returns this:

me@myPC:~/test$ ./main 
/dev/port -1
/dev/port Operation not permitted
Open ok: /dev/tty0

with these permission rights

me@myPC:~/test$ ll /dev/tty /dev/port 
crw-rw-rw- 1 root kmem 1, 4 Sep 12 14:32 /dev/port
crw-rw-rw- 1 root tty  5, 0 Sep 12 15:51 /dev/tty
  • 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-11T06:44:01+00:00Added an answer on June 11, 2026 at 6:44 am

    To open /dev/port you need the capability CAP_SYS_RAWIO, in addition to permission to open the file.

    drivers/char/mem.c:730
    
    static int open_port(struct inode * inode, struct file * filp)
    {
        return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
    }
    

    You can either gain this by being root or by setting it for a single executable (similar to set-uid) using setcap.

    http://linux.die.net/man/8/setcap

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

Sidebar

Related Questions

I'm currently working on a database which is rather complex, at least for my
I'm working on an academic project which simulates a rather large queuing procedure in
I'm working on a rather complex report in Sql Server Reporting Services. My SP
I have a large old program which has some rather complex graphical displays (all
I'm working on converting a rather complex .NET WinForms program into a fully-integrated SQL
Problem domain I'm working on a rather big application, which uses a hierarchical data
Please tear this code apart, make it complex and scarcely readable, I'd rather learn
I'm working at a complex script which could be processing upto 500,000 records. Here's
I'm working on (what is to a beginner) a rather complex assignment. I think
I'm working on a C# .NET application that uses some rather complex scientific formulas

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.