Problems caused by C programming rename functions under Linux

Source: Internet
Author: User

Some time ago, when deploying code, we found a more "weird" problem.

In the same environment (CentOs 6.5), development says that the virtual machine rollup tests in its native computer are normal and when deployed into a formal environment, problems arise. The same function, which always fails to execute. In another test, it's perfectly normal.

Development is said to be the cause of server installation, to go back and forth installed n times. Real TM Depressed

Then said is the authority of the problem, the package of problems, their own installation, the server take home upgrade, re-buy the server, this take back to his mother and so on and so on ... I've been lazy about him.

First of all, say permissions, I said the test is the normal machine exactly the same, said no, okay, give you 777

Also said that the package did not install, I said that bag, said do not know, ...

Toss a few days are not installed, and said to disturb his ideas, brother is a DBA, not SA, is also no language

Solve:

Finally because of the near-line, there is no way, take his code to see if you can find the reason, is sure that the package, permissions do not have any problems. Personally think that is the problem of the code (what this guy often says is: Don't doubt my Code)

The key does not show any valid information in the log, but returns the function execution failure value-1, which has no value at all.

In the Linux system programming Chinese version. PDF to see the functions he used

#include <stdio.h>intmain (const char *oldpath,const char *newpath);

A successful call to rename () renames the pathname OldPath to NewPath, the file contents and Inode remain unchanged, and theOldPath must be the same file system as the NewPath predicate. Otherwise, the call fails.

You can also set errno for progressive troubleshooting, and the following are explanations of errno

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/70/F6/wKiom1XB0rzTE5xWAAP61pij1I8235.jpg "title=" 1112015-08-05_170503.png "alt=" Wkiom1xb0rzte5xwaap61pij1i8235.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/70/F3/wKioL1XB1NWwsJ37AAIyxLsMVTI968.jpg "title=" 2015-08-05_170729.png "alt=" Wkiol1xb1nwwsj37aaiyxlsmvti968.jpg "/>

This is the focus, so that the basic solution to the problem, if in the event of an error, set up the errno, for finding the problem is also very helpful.

Because the program is running, OldPath and NewPath are completely different file systems, in fact, partitions are different.

OldPath is located in/home/test----/DEV/SDA1

NewPath is located in/var/www/photo----/DEV/SDA3


Then modified the program two paths, instead of the same partition, OK, problem solving

The emergence of this problem, the personal feel is that development does not fully understand the rename function, just know that there is this usage, can use, but do not know what to pay attention to matters.

Solve the problem, the idea must be clear, in response to the problem of one to be excluded, certainly can be solved!

This article is from "The girl said" blog, please be sure to keep this source http://sugarlovecxq.blog.51cto.com/6707742/1681973

Problems caused by C programming rename functions under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.